How to make an animation play on click when sitting in a seat?

I want to know how I could make a script where a player can click on the screen and play an animation only when sitting on a seat, Ive tried multiple times and I cant find a solution.
Please help me get a solution!

1 Like

Have you tried using the animation priority?

Yea but thats not my issue, im wondering how i can play a animation when the player clicks while sitting on a specific seat

so, I would get the Humanoid.SeatPart when it changes, if it is nil, it isn’t sitting, otherwise check if it is the specific seat.

Reference: Humanoid | Documentation - Roblox Creator Hub

I think this is the solution but ive got a bit more questions, where should i put the script inside of? The seat part itself, or somewhere like ServerScriptService or StarterCharacterScripts?

1 Like

Starter character scripts, if you want to do script.Parent.Humanoid, otherwise you do the player event and get the character

1 Like

what is a better method, if i plan having multiple seats?

Either way works, but if there is multiple seats, I would make a table pointing to each seat, and loop through when changed to see if one of them is the value.

(sorry for the late response)

EDIT: there might be another late one.

To give you a perspective, im trying to make a gym system with pull up bars, benchpress’s, dead lifts etc., and i dont want to make it too advanced so thats why i want it just to play a idle animation while sitting and on click plays a animation for each workout

If you don’t want it too advanced, probably just put it in the StarterCharacterScripts then.

EDIT: based off of the things you want you basically only have that option out of the two.

alr, could you show me an example of how to loop though the seats?

Sure thing

local seats = {game.Workspace:WaitForChild("Seat1"), game.Workspace:WaitForChild("Seat2"), game.Workspace:WaitForChild("Seat3")}
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local sitting = false

humanoid:GetPropertyChangedSignal("SeatPart"):Connect(function()
    if table.find(seats, humanoid.SeatPart) then
        sitting = true
    else
        sitting = false
    end
end)

Sorry, i pressed enter accidentally too early.

and how could i specifically find the seat that i want to use with the table? sorry to ask, i dont understand tables and how they work well enough

I’m assuming you know how to get an object by its path, so you would just take its path and put it in the table, each entry ends with a comma to split them. like this: `{“Hello”, “World!”}

Ive made my script work and it works with all of the seats which is great since I can make this system with the rest of my gym equipment!

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