How to disable jumping out of a "Sit" position?

I need help with trying to disable player jumping when trying to get out of a “Sit” position, which you can enable in humanoid properties. I’m not asking for whole scripts. Thanks for help!

1 Like

You can use Humanoid.StateChanged to check the humanoid’s state and Humanoid:GetState() to check what state the humanoid is currently in, and then you can set the JumpPower to 0 if their state was Enum.HumanoidStateType.Seated before.

5 Likes

Example, adapt this, and it can be on a server script or in a local script, depending on your needs:

local humanoid = character:WaitForChild("Humanoid")
local MaxJumpPower = 16 -- or whatever your jump power is.
humanoid.StateChanged:Connect(function(oldState, newState)
     if newState == Enum.HumanoidStateType.Seated then
         humanoid.JumpPower = 0
     elseif oldState == Enum.HumanoidStateType.Seated then
         humanoid.JumpPower = MaxJumpPower
     end
end

Edit: If I recall correctly, there is also directly a property for the Seated under the humanoid, you can specifically do something like this, this is another example for how you can get that result:

humanoid:GetPropertyChangedSignal("Seated"):Connect(function()
        if humanoid.Seated == true then
           humanoid.JumpPower = 0
        else
           humanoid.JumpPower = MaxJumpPower 
        end
end)
3 Likes

As a heads up, the Roblox Creator Documentation site advises against updating either Humanoid.JumpPower or Humanoid.JumpHeight to disable the Character’s ability to jump.

It recommends using Humanoid:SetStateEnabled() to achieve that, instead. (But I guess if you really want to be sure it has the intended effect, you could always pair this and updating either JumpPower / JumpHeight at the same time.)


Example

-- Disables the Character's ability to jump
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)

-- Allows the Character to jump
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
2 Likes

Sorry for the late reply but I drafted this at that time but just posting now.

Wow, this is actually interesting! Thanks for the heads-up! It actually makes sense as to why Roblox recommends Humanoid:SetStateEnabled().

So, the likely reason Roblox might be advising us to do this instead of setting JumpPower or JumpHeight manually, is because it will take care of additional stuff, so probably more reliable, because when we manually change the property to 0, it is actually modifiable by an exploiter, and they can change it and literally be able to jump… Which is not secure…

It’s the opposite for the method recommended by Roblox (I think)
That method SetStateEnabled() actually sets if the jumping state is even possible/available for that specific humanoid, or not. directly on the server, which is actually great! It makes it harder for exploiters to bypass that specific security, and it’s likely more secure this way for the intended effect, and I think even games like DOORS also use this way for this reason! And this way of implementation likely has to be done on the server-side, so at the end, I’d say the best choice might depend on our game system, but SetStateEnabled() is definitely secure

1 Like