Keeping The Player Seated

Hey y’all,

I’m working on my own submarine, and I’ve reached a complication. I’m having trouble preventing the player from jumping from their seat. Like any other seat, you sit on it, and press the Spacebar to jump. I’d like to move the dismount key to Backspace as opposed to the Spacebar, so that the Spacebar can be used to raise the submarine.

I’ve attempted to set the JumpPower to 0, I’ve tried making my own additional weldconstraint between the humanoidrootpart and the seat, and I’ve tried disabling the Jumping state with SetStateEnabled. None of these have worked.

2 Likes

I am unsure if PlayerModule:GetControls():Disable() will disable jumping out of a seat or not, worth a try… it may also disable vehicle seat input, though.

You could try utilizing ContextActionService to temporarily override the spacebar input to jump, and then re-bind jumping to backspace. Check out the functions here.

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 = players.LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
 
-- Fires when the user tries to jump
local function Jump()
    humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
end
 
userInputService.JumpRequest:Connect(Jump)

(Example from the Developer Hub)

14 Likes

This question has been asked several times over. Please search the DevForum first before asking. This is a post from some time ago where I explain how you can stop player jumping.

For quick reference without opening the post, these are the methods I proposed:

  • Setting JumpPower to 0
  • Forcing the Humanoid’s Jump property to false
  • Forcing the Humanoid’s Jump state not to enable (or disabling it)
  • Sinking the input for the space bar input using ContextActionService
  • Using the explicit disable jump code from UserInputService.JumpRequest (which could be found by using the search bar)
8 Likes

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

2 Likes

Update: I’ve found that it only works when the seat is anchored. It does not work if the seat is unanchored, and welded to the submarine. I’ve tried both a WeldConstraint, and by changing the BottomSurface of the seat to Glue and Weld.

Unfortunately, the submarine cannot move without be unanchored altogether.

Context seems to work out. Thank you, and thanks to everyone who helped out !

2 Likes

Okay, so the following works at disabling:
ContextActionService:UnbindAction("jumpAction")

But how would I re-enable it so that JumpRequest and jumping still works?

ContextActionService:BindAction("Jump", JumpButtonAction, false, Enum.KeyCode.Space)

1 Like

You should use this instead:

local jumpDisabled = false

ContextActionService:BindActionAtPriority("JumpOverride", function()
    if jumpDisabled then
        return Enum.ContextActionResult.Sink
    else
        return Enum.ContextActionResult.Pass
    end
end, false, Enum.ContextActionPriority.High, Enum.PlayerActions.CharacterJump, Enum.KeyCode.Space)

Then you can just set jumpDisabled to true or false.

EDIT: Corrected to Enum.PlayerActions.CharacterJump

This is extra nice because you can then hook in your submarine control right there where it returns Sink.

9 Likes

Is JumpOverride a CoreScripts function? I can’t seem to find any documentation on it.

No, this binds a new action that overrides the default jump action.

1 Like

Thank you both for helping! Fortunately, I figured it out. :slight_smile:

3 Likes

would you put this script inside the seat or serverscript or where

2 Likes

Update to this thread, setting the JumpHeight property to zero does work for me.

2/22/2023

Use ContextActionService instead.

that requires the client to get involved, which is not ideal for me. is using the client the only way to stop them jumping out of sitting?