When you use this method of preventing someone from controlling, they cannot jump, but they are still able to jump. You can make them jump when they press a key, you can detect when they press a key though KeyDown or UnserInputService.
Making a player jump
There is a way to force a player to jump, In the humanoid there is a Jump property which is a boolean. If it is true, the player jumps once.
1 | workspace.Player.Humanoid.Jump = true |
Fun Facts about Jump property
- You can make an anti-jump script using the changed event:
1 | workspace.Player.Humanoid.Changed:connect( function (jump) |
3 | workspace.Player.Humanoid.Jump = false |
KeyDown
It's deprecated, you shouldn't use it.
2 | local plyr = game:GetService( "Players" ).LocalPlayer |
3 | local mouse = plyr:GetMouse() |
5 | mouse.KeyDown:connect( function (key) |
6 | if key:byte() = = 32 then |
7 | plyr.Character.Humanoid.Jump = true |
Fun Facts about KeyDown
- There is KeyUp which is not as popular as KeyDown.
UserInputService
Use InputBegan to see what keys the player pressed:
2 | local plyr = game:GetService( "Players" ).LocalPlayer |
3 | local uis = game:GetService( "UserInputService" ) |
5 | uis.InputBegan:connect( function (key) |
6 | if key.KeyCode = = 32 then |
7 | plyr.Character.Humanoid.Jump = true |
Fun Facts about UserInputService
- You can now play roblox with a game console because of user input service!
Final Script
02 | local plyr = game:GetService( "Players" ).LocalPlayer |
03 | local uis = game:GetService( "UserInputService" ) |
05 | for _, controller in pairs (game:GetService( "ControllerService" ):GetChildren()) do |
09 | uis.InputBegan:connect( function (key) |
10 | if key.KeyCode = = Enum.KeyCode.Space then |
11 | if plyr.Character:FindFirstChild( "Humanoid" ) then |
12 | plyr.Character.Humanoid.Jump = true |
Hope this helps!