Trying to make a script that when you press "W" you'll jump

I’m trying to help my friends with a platformer and i’m having an issue with a script I made
image
when the player presses “W” he wouldn’t jump.
any suggestions?

3 Likes

Turn the jump property of the players humanoid to true, make sure to use a remote event.

2 Likes

What should I use the remote event for?

1 Like

To change the property on the server

1 Like

Can you be more specific of what I should do with it?

1 Like
RemoteEvent.OnServerEvent:Connect(function(Player)
Player.Character.Humanoid.Jump = true

end)

Fire the remote event from the client when they press w

It shows this error.

image

You are suppose to have that in a server script

Local script:

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(Input, Typing)
	if Typing == false then
		if Input.KeyCode == Enum.KeyCode.W then
			game.ReplicatedStorage.Jump:FireServer()
		end
	end
end)

SeverScript:

game.ReplicatedStorage.Jump.OnServerEvent:Connect(function(Player)
	Player.Character.Humanoid.Jump = true
end)

2 Likes

Manually setting the Humanoid’s jump property to true doesn’t always force the player to jump.
You should instead use Humanoid:ChangeState()

UIS.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.W then
		humanoid:ChangeState(Enum.HumanoidStateType.Jumping)    		
	end
end)

It actually does, I have testing it and it works

Maybe, but Humanoid:ChangeState() is a better option. It is easier to use and doesn’t need an event to replicate on the server.

1 Like