So basically i want to make this script lua roblox work properly and add velocity offset…
- User
So basically i want to make this script lua roblox work properly and add velocity offset by 0.197 while true do heartbeat:Wait() if target == true then local character = game.Players[targetplr].Character.HumanoidRootPart local lastPosition = character.Position task.wait() local currentPosition = character.Position local velocity = (currentPosition - lastPosition) * 0 character.AssemblyLinerVelocity = velocity character.Velocity = velocity end end
- Assistant
To make the script work properly and add a velocity offset of 0.197, there are a few key improvements and adjustments you need to consider. Here is a refined version of your script:
- The calculation of velocity should correctly determine the movement over a time period.
- The velocity offset should be added.
- Ensure that
targetplris defined and valid. - Correct the velocity setting to
AssemblyLinearVelocity.
Here is the improved script:
-- Replace 'heartbeat' with 'RunService.Heartbeat' local RunService = game:GetService("RunService") local target = true -- Ensure you set this variable as needed in your script local targetplr = "Player" -- Replace "Player" with the target player's name local lastPosition RunService.Heartbeat:Connect(function() if target then local player = game.Players:FindFirstChild(targetplr) if player and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then local character = player.Character.HumanoidRootPart if lastPosition then local currentPosition = character.Position local velocity = (currentPosition - lastPosition) / RunService.Heartbeat:Wait() -- Calculating velocity velocity = velocity + Vector3.new(0, 0.197, 0) -- Adding the offset character.AssemblyLinearVelocity = velocity -- Optional: You might not need the line below if 'AssemblyLinearVelocity' does the job. -- character.Velocity = velocity lastPosition = currentPosition else lastPosition = character.Position end else lastPosition = nil end end end)Explanation:
- Run Service: Utilize
RunService.Heartbeatfor frame updates. - Target Player Validation: Ensure
targetplris a valid player and their character exists. - Velocity Calculation: Correctly calculates the velocity based on position differences and adds the offset (
+ Vector3.new(0, 0.197, 0)). - Tracking Position: Keeps track of the character's last position to calculate movement velocity accurately.
Replace
targetplrvalue with the actual player's name or set it dynamically as per your requirements. This script continuously updates the player's velocity with an added offset, making sure that the movement calculation is done correctly.