Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i make the velocity go up?

it says all the time that i need vector3.new but i need to add velocity from existing velocity, here is my local script

print("ready")

player = game:GetService("Players").LocalPlayer.Character:WaitForChild("HumanoidRootPart")

  

local Player = game.Players.LocalPlayer

local mouse = Player:GetMouse()

  

mouse.KeyDown:Connect(function(key)

local Key = key.lower("e")

if key == ("e") then

player.Velocity = Vector3.new(player.Velocity + 0, 10, 0)

end

end)

  

mouse.KeyDown:Connect(function(key)

local Key = key.lower("q")

if key == ("q") then

player.Velocity = Vector3.new(player.Velocity + 0, -10, 0)

end

end)

1 answer

✓ Accepted answer

You would want to modify the velocity like this:

player.Velocity = player.Velocity + Vector3.new(0,10,0)

This way you are saying that you want the velocity to be what it currently is, but then you add a Vector3 value. The computer was confused before because it thought you were just adding numbers.

Also the method you used of modifying a part's velocity will work if it's a part, but I don't think that method will work with a player. What I've done is used "BodyVelocity" which is a body mover. First I create it inside of the humanoid root part and then I modify the Velocity of the Body Velocity.

Here is the full script:

local Player = game:GetService("Players").LocalPlayer

local char = Player.Character or Player.CharacterAdded:Wait()

local root = char:WaitForChild("HumanoidRootPart")

  

local mouse = Player:GetMouse()

  

local bodyVelocity = Instance.new("BodyVelocity", root)

bodyVelocity.Velocity = Vector3.new(0,0,0)

mouse.KeyDown:Connect(function(key)

  

	local Key = key.lower("e")

  

	if key == ("e") then

		bodyVelocity.Velocity = bodyVelocity.Velocity + Vector3.new(0, 10, 0)

	end

  

end)

  

  

mouse.KeyDown:Connect(function(key)

  

	local Key = key.lower("q")

	if key == ("q") then

		bodyVelocity.Velocity = bodyVelocity.Velocity + Vector3.new(0, -10, 0)

	end

  

end)

This discussion is preserved as it was. New answers, comments, and votes are closed.