Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I disable jumping when the player is seated?

This script is in a LocalScript inside of StarterCharacterScripts

local player = game.Players.LocalPlayer
local character = player.Character
character:WaitForChild("Humanoid")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

function onSeated(isSeated, seat)
	if isSeated then
		character.Humanoid.Jump = false
	else
		character.Humanoid.Jump = true
	end
end
humanoid.Seated:Connect(onSeated)

1 comment

0

You may use ContextActionService to temporarily unbind the Jump event. local ContextActionService = game:GetService('ContextActionService') ContextActionService:UnbindAction("jumpAction") Alternatively you can use this approach with UserInputService. -- Services local userInputService = game:GetService("UserInputService") local players = game:GetService("Players") -- Local player local player

2 answers

✓ Accepted answer

You don't use Jump property for that, this bool property becomes true whenever you hold the jump button and becomes false whenever you release it. Changing it does not change anything, it resets every render. To disable jumping, use JumpPower, just set it to 0. Also you have variable character.Humanoid defined as humanoid so you can use it.

local DefaultJumpPower = humanoid.JumpPower

function onSeated(isSeated, seat)
    if isSeated then
        humanoid.JumpPower = 0
    else
        humanoid.JumpPower = DefaultJumpPower
    end
end
humanoid.Seated:Connect(onSeated)

The DefaultJumpPower stands for the default jump power of the humanoid, you don't need to have it, instead you can have 50 as it's the default unless you change it but it's still better with it.

Well, there was a little flaw in your script. When the player sits, the if statement triggers then only, and not when the player uses a key or touch to 'Jump'. Here's what your must do, with explanation :

local player = game.Players.LocalPlayer
local character = player.Character
character:WaitForChild("Humanoid")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
 
local function onJump() -- Creating a custom local function
	if humanoid.Jump then -- If humanoid was triggered to jump
		humanoid.Jump = false -- Makes it false, as soon as it becomes true, to disable the humanoid to jump
	end
end

function onSeated(isSeated, seat)
	if isSeated then
		humanoid:GetPropertyChangedSignal('Jump'):Connect(onJump) -- GetPropertyChangedSignal triggers when a property in () parathesis changes. 
	end
end

humanoid.Seated:Connect(onSeated)

Lemme know if it helps!

3 comments

1

This is redundant and stupid, to be honest. SetStateEnabled() completely replaces this.

0

Well, there are a lot of methods to fix his issue. But, I try my best to have the contents of the solution to what the asker has tried.

0

When I stop sitting, it doesn't let me jump anymore

This discussion is preserved as it was. New answers, comments, and votes are closed.