I made a code that makes an animation play right after the character stops falling. the animation takes about two seconds. i set WalkSpeed to zero to prevent the character from moving. So far so good.
However, the character can still jump. i then tried setting JumpPower and JumpHeight to zero of which only JumpHeight seemed to work.
humanoid.StateChanged:Connect(function(old, new)
if old == Enum.HumanoidStateType.Freefall then
humanoid.WalkSpeed = 0
--humanoid.JumpPower = 0
humanoid.JumpHeight = 0
kickAnimationTrack:Play()
task.wait(2)
kickAnimationTrack:Stop()
humanoid.WalkSpeed = 16
--humanoid.JumpPower = 50
humanoid.JumpHeight = 7.2
end
end)
My question is, is setting JumpHeight to zero the best way to prevent a character from jumping while an animation is playing? Are there better or safer alternatives?
I may be wrong but another way of doing this is within the game settings. You should be able to find a “Jump Power” setting somewhere under Avatar.
I may be wrong about that though
If this is the case I would do that instead of a script. otherwise I think the script should work fine
EDIT: I appear to have misread the topic. After rereading the post it seems that would be a good way to do it. I can’t really think of any other way of doing it.
Considering character input and physics are controlled by the client, there’s no way to guarantee the prevention of jumping unless you perform some checks on the server (exploiters will find a way to break the system). That being said, setting the jump power to zero is a simple and effective way to stop most players from jumping. If you want to be a little more thorough, you could unbind the jump action using ContextActionService.
You could use the JumpRequest event from UserInputService which is what I use.
I made mine using a loop and jump request, although I could probably think of a method that doesn’t use a loop, it’s there just for exploiters who don’t set jump power every frame. I use this method instead of just disabling the Jumping state mostly because exploiters can just reenable states.