Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make the velocity go up?

Asked by 6 years ago

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

01print("ready")
02 
03player = game:GetService("Players").LocalPlayer.Character:WaitForChild("HumanoidRootPart")
04 
05   
06 
07local Player = game.Players.LocalPlayer
08 
09local mouse = Player:GetMouse()
10 
11   
12 
13mouse.KeyDown:Connect(function(key)
14 
15local Key = key.lower("e")
16 
17if key == ("e") then
18 
19player.Velocity = Vector3.new(player.Velocity + 0, 10, 0)
20 
21end
22 
23end)
24 
25   
26 
27mouse.KeyDown:Connect(function(key)
28 
29local Key = key.lower("q")
30 
31if key == ("q") then
32 
33player.Velocity = Vector3.new(player.Velocity + 0, -10, 0)
34 
35end
36 
37end)

1 answer

Log in to vote
1
Answered by
vissequ 105
6 years ago

You would want to modify the velocity like this:

1player.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:

01local Player = game:GetService("Players").LocalPlayer
02 
03local char = Player.Character or Player.CharacterAdded:Wait()
04 
05local root = char:WaitForChild("HumanoidRootPart")
06 
07 
08 
09local mouse = Player:GetMouse()
10 
11 
12 
13local bodyVelocity = Instance.new("BodyVelocity", root)
14 
15bodyVelocity.Velocity = Vector3.new(0,0,0)
16 
17mouse.KeyDown:Connect(function(key)
18 
19 
20 
21    local Key = key.lower("e")
22 
23 
24 
25    if key == ("e") then
26 
27        bodyVelocity.Velocity = bodyVelocity.Velocity + Vector3.new(0, 10, 0)
28 
29    end
30 
31 
32 
33end)
34 
35 
36 
37 
38 
39mouse.KeyDown:Connect(function(key)
40 
41 
42 
43    local Key = key.lower("q")
44 
45    if key == ("q") then
46 
47        bodyVelocity.Velocity = bodyVelocity.Velocity + Vector3.new(0, -10, 0)
48 
49    end
50 
51 
52 
53end)
Ad

Answer this question