How do you know when a player is in a seat?

I’m trying to make it so that when the local player is in a seat and the W key is pressed the model the player is sitting in moves forward.

When I run the script nothing happens and I believe it’s something to do with the start of the if statement.

I’v searched it up on the internet but couldn’t find anything that could benefit me.

It’s probably really easy to solve. I’m still learning scripting.

Well, you can check every time a player is seated or unseated with this:

local character = --Path for character
local humanoid = character:WaitForChild("Humanoid")

local function onSeated(isSeated, seat)
    if isSeated then
        -- Put a connection with the uis

    else
        -- player is not sitting anymore (idk if you need this)
    end
end

humanoid.Seated:Connect(onSeated)
1 Like

Adding on to what paetemc2 said:

local character = --Path for character
local humanoid = character:WaitForChild("Humanoid")
local Connection = nil

local function onSeated(isSeated, seat)
    if isSeated then
        Connection = UIS.InputBegan:Connect(function(input, gameProcessedEvent)
            if input.UserInputType == Enum.UserInputType.Keyboard then
                if input.KeyCode == Enum.KeyCode.W then
                    CannonSeat.Parent.PrimaryPart.CFrame = CannonSeat.Parent.PrimaryPart.CFrame + CannonSeat.Parent.PrimaryPart.CFrame.LookVector
                end
            end
        end
    else
        Connection:Disconnect()
    end
end

humanoid.Seated:Connect(onSeated)

(I added the remaining code and added a connection/disconnect thingy)

You can also check if the user is seated with Humanoid.Seated

Thanks for the help, I realised that the reason why it wasn’t working with your script was because I needed to put it in starter character scripts instead of starter player scripts

should this script be local or server and where do I place it. Sorry for the trouble im just a beginner in roblox studio