How can I get this Linear Velocity to work?

How can I get this Linear Velocity to move the player where they are facing? Currently the player is not even moving. I’m a rookie when it comes to physics so I’d appreciate any help.

UserInputService.InputBegan:Connect(function(input, gameProccessedEvent)
	if gameProccessedEvent then return end 
	if input.KeyCode == Enum.KeyCode.LeftShift and debounce == false then 
		if character.Humanoid.Health > 0 then 
			print("Running")
			debounce = true 
			local dashAnimation = ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Dash")
			local bodyVelocity = Instance.new("LinearVelocity", character:FindFirstChild("HumanoidRootPart"))
			bodyVelocity.MaxForce = 1000000000000
			bodyVelocity.VectorVelocity = character.HumanoidRootPart.CFrame.LookVector * 50
			print("linear velocity made")
			task.wait(1)
			debounce = false
		end
	end
end)
1 Like
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local character = script.Parent
local debounce = false

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then return end
	if input.KeyCode == Enum.KeyCode.LeftShift and not debounce then
		if character and character:FindFirstChild("Humanoid") and character.Humanoid.Health > 0 then
			print("Running")
			debounce = true

			local Dash = ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Dash")
			local HumanoidRootPart = character:FindFirstChild("HumanoidRootPart")

			local BodyVelocity = Instance.new("BodyVelocity")
			BodyVelocity.Velocity = HumanoidRootPart.CFrame.LookVector * 50
			BodyVelocity.MaxForce = Vector3.new(4000, 4000, 4000) 
			BodyVelocity.P = 1250
			BodyVelocity.Parent = HumanoidRootPart

			task.delay(1, function()
				if BodyVelocity then
					BodyVelocity:Destroy()
				end
				debounce = false
			end)
		end
	end
end)

Hi, try this! Hope this works, I updated your script to use the BodyVelocity to move the player in the direct they’re facing.

1 Like

Body velocity is depracated and not recommended to use, linear velocity is the replacement.

The problem is linear velocity requires an attachment to work without one it wont apply the force. Try this code instead:

UserInputService.InputBegan:Connect(function(input, gameProccessedEvent)
	if gameProccessedEvent then return end 
	if input.KeyCode == Enum.KeyCode.LeftShift and debounce == false then 
		if character.Humanoid.Health > 0 then 
			print("Running")
			debounce = true 
			local dashAnimation = ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Dash")

            local att = Instance.new "Attachement"
            att.Parent = chatacter.HumanoidRootPatt
 
			local bodyVelocity = Instance.new("LinearVelocity", character:FindFirstChild("HumanoidRootPart"))
            bodyVelocity.Attachement0 = att 
			bodyVelocity.MaxForce = math.huge
			bodyVelocity.VectorVelocity = character.HumanoidRootPart.CFrame.LookVector * 50
			print("linear velocity made")
			task.wait(1)
			debounce = false

            bodyVelocity:Destroy()
            att:Destroy()

		end
	end

1 Like

Thanks for the solution! I’m pissed that it was that simple, I appreciate it though.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.