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

My jumping script won't work?

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)

1 comment

0

Accept the answer maybe? Accepting the answer gives you and I 1 reputation.

1 answer

✓ Accepted answer

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!

1 comment

0

Thx man! :D

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