Answered by
5 years ago Edited 5 years ago
It's not very complicated.
You just need to understand how to get a player's keypress and need to understand remote events.
Make sure this is a local script inside of startergui:
04 | local player = game.Players.LocalPlayer |
05 | local character = player.Character or player.CharacterAdded:Wait() |
06 | local humanoid = character:WaitForChild( "Humanoid" ) |
07 | local mouse = player:GetMouse() |
09 | local jumpEvent = game:GetService( "ReplicatedStorage" ):WaitForChild( "jumpEvent" ) |
11 | mouse.KeyDown:Connect( function (key) |
12 | if string.lower(key) = = "w" then |
13 | jumpEvent:FireServer() |
Make sure this is a server script:
3 | local jumpEvent = Instance.new( "RemoteEvent" , game:GetService( "ReplicatedStorage" )) |
4 | jumpEvent.Name = "jumpEvent" |
6 | jumpEvent.OnServerEvent:Connect( function (player) |
8 | player.Character.Humanoid.Jump = true |
The reason we need two scripts is because server scripts cannot get a player keypress and local scripts cannot make the player jump. So we use the remote events to let them communicate to each other.