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

My jumping script won't work?

Asked by
Mr1Vgy 30
9 years ago

Ok so I have taken away the player's control of their character using the ControllerService, and now I want to make it so that when the player presses the space key, their character jumps. I have this in a LocalScript and it doesn't work. Can anyone figure out why? It works if I use a different key, but I want to use space.

game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key)
    if key == Enum.KeyCode.Space then
        if plr.Character:FindFirstChild("on")then
            plr.Character.Humanoid.Jump = true
            print("jumped")
        end
    end
end)
0
Accept the answer maybe? Accepting the answer gives you and I 1 reputation. EzraNehemiah_TF2 3552 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

There is no such thing as Enum.KeyCode.Space. Instead use string.byte().

game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key)
    if key:byte() == 32 then --The code for space is 32.
        if plr.Character:FindFirstChild("on") then
            plr.Character.Humanoid.Jump = true
            print("jumped")
        end
    end
end)

How do I know that space is 32? Well just look on this chart, please note that some of the things on this chart do not work. BTW there are 4 different number columns, look under the one that says Dec on the top.


Hope this helps!

0
Thx man! :D Mr1Vgy 30 — 9y
Ad

Answer this question