Jump script only applies once

I have a script in a drive seat, that makes the player’s JumpPower go to 0 because the car needs the spacebar for the handbrake.
But when I enter the car again, it doesn’t change the JumpPower but it does print like if it did work.

This is the script

script.Parent.Changed:Connect(function()
	if script.Parent.Occupant ~= nil then
		script.Parent.Occupant.JumpPower = 0
		print("Test")
	end
end)

I tried changing the 3rd line many times and same results. I also tried disabling some other scripts (f to leave) but still the same

Help

1 Like

Can you send the surrounding lines of code? Where is the script parented to?

That’s the entire script. Its located inside a DriveSeat.
It works the first time but not after that.

Is it a server script? What is the Occupant (class name)?

It is. The occupant is a humanoid in this case mine

You can use the humanoid’s State to check if they are sitting down.

humanoid.StateChanged:Connect(function(old, new)
    if new == Enum.HumanoidStateType.Sitting then
        humanoid.JumpHeight = 0
    else
        humanoid.JumpHeight = --default jump height here
    end
end)

To be honest, I would recommend you to use SetStateEnabled(state, bool) function.
example line :

Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)

This will disable player jumping.

Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)

this will enable player jumping

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.