In my game I wanted to make it so that characters cannot hold spacebar to jump and if they have some sort of status effect that’s supposed to make them unable to jump, they wouldn’t be able to jump. I could make their JumpPower 0 but that would inevitably cause wierd bugs where characters jump too high or too low.
I have a remoteEvent set up so that when a player presses the space bar, it fires and the server makes their JumpPower 50 and forces them to jump. The main problem here is that there’s a jump delay when more players are in the server. It’ll wait about 0.1 seconds or so then make the character jump. I don’t know a good way to fix this.
Is there any way I can prevent players from holding the spacebar to jump and make the player unable to jump when they have a certain status effect without making their jump power 0?
the remoteevent has delay due to the server being in a different location than the client, and this delay can be over a second in some cases. You can instead use the same space bar detection code and take the server code that makes the jump and move it to the client under the input code. While you might think this is a bad practice, it doesn’t change anything, as exploiters could already jump if they wanted to during a disallowed time using your old system, since the client has full control over it’s humanoid.
To prevent holding to jump simply do something like this:
userinputservice.InputBegan:Connect(function(Input)
if Input.KeyCode.Name == "Space" then
Jump()
end
end)
this will only fire when they press it, then they need to release and press it back down to jump again.
Make them unable to jump by simply making their jumppower 0. I don’t see why this isn’t a good solution. Just store their old JumpPower in a variable and retrieve it later once they jump again and you’ll have good control over how and where they can jump.
setting their JumpPower to 0 isn’t a good solution because there are status effects that can lower or disable your jump, and it can and has caused a lot of jump height related bugs. Not to mention the jump button won’t appear on mobile if the JumpPower is 0