Hi, I'm extremely new to roblox coding and I want to make a traditional fighting game. The first thing I'm trying to do is make it so W jumps and S crouches, but I'm not even sure where to start. I'm sure it's possible because in the "Infinite Runner" preset game you use W to jump. I don't have any code to show because I haven't been able to find anything related to my problem. Thanks!
✓ ANSWER ACCEPTED
How do I bind "W" to jump using scripts?
1 answer
✓ Accepted answer
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:
--LOCAL SCRIPT
--PUT THIS SCRIPT INSIDE OF STARTERGUI
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local mouse = player:GetMouse()
local jumpEvent = game:GetService("ReplicatedStorage"):WaitForChild("jumpEvent") --Waits for the remoteEvent to be created by the server
mouse.KeyDown:Connect(function(key)
if string.lower(key) == "w" then
jumpEvent:FireServer() --send a message to the server to tell the player to jump
end
end)
Make sure this is a server script:
--SERVER SCRIPT
local jumpEvent = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage")) -- create the remoteEvent
jumpEvent.Name = "jumpEvent"
jumpEvent.OnServerEvent:Connect(function(player) -- receive the message from the local script
print("Jumped")
player.Character.Humanoid.Jump = true
end)
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thank you so much!