Hi I'm creating sort of a 2D Endless Runner game, and I'm using this method... : http://wiki.roblox.com/index.php?title=Controlling_a_Player%27s_Character to make the player move on its own. However, if you use WASD or Arrow keys, that cancels the movement, and removing all control no longer allows you to jump. Is there a way to remove all WASD/Arrow Keys control while still being able to jump?
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.
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.
workspace.Player.Humanoid.Jump = true
workspace.Player.Humanoid.Changed:connect(function(jump) if jump == "Jump" then workspace.Player.Humanoid.Jump = false end end)
It's deprecated, you shouldn't use it.
--LocalScript local plyr = game:GetService("Players").LocalPlayer local mouse = plyr:GetMouse() mouse.KeyDown:connect(function(key) if key:byte() == 32 then --32 is space. plyr.Character.Humanoid.Jump = true end end)
Use InputBegan to see what keys the player pressed:
--LocalScript local plyr = game:GetService("Players").LocalPlayer local uis = game:GetService("UserInputService") uis.InputBegan:connect(function(key) if key.KeyCode == 32 then plyr.Character.Humanoid.Jump = true end end)
--LocalScript local plyr = game:GetService("Players").LocalPlayer local uis = game:GetService("UserInputService") for _, controller in pairs(game:GetService("ControllerService"):GetChildren()) do controller:Destroy() end uis.InputBegan:connect(function(key) if key.KeyCode == Enum.KeyCode.Space then if plyr.Character:FindFirstChild("Humanoid") then plyr.Character.Humanoid.Jump = true end end end)
Hope this helps!
InputBegan
Event of UserInputServiceThis Event detects any user input. If you compare the value returned(the user input) with any KeyCode Enum, in your case.. 'Space', then you can activate the Jump
Property of the character's Humanoid. this will make them jump
--UserInputService local uis = game:GetService('UserInputService') --Player local plr = game.Players.LocalPlayer --InputBegan uis.InputBegan:connect(function(input) --Check if the input is space if input.KeyCode == Enum.KeyCode.Space then --Activate Jump property local hum = plr.Character:WaitForChild('Humanoid') if hum then hum.Jump = true end end end)