Im trying to make it so that when a player sits in a seat, a animation is applied to them.
local seat = script.Parent function SeatIsSatIn(hit) if hit.Parent:FindFirstChild("Humanoid") then local character = hit.Parent local humanoid = character.Humanoid wait(0.5) if humanoid:GetState() == Enum.HumanoidStateType.Seated then local animation = Instance.new("Animation") animation.AnimationId = "http://www.roblox.com/asset/?id=182435998" local track = humanoid:LoadAnimation(animation) track:Play() local function StateChanged(oldState, newState) if newState ~= Enum.HumanoidStateType.Seated then track:Stop() end end humanoid.StateChanged:connect(StateChanged) end end end seat.Touched:connect(SeatIsSatIn)
I made this script a year ago when I was 8, it may not work, and it didnt..... Whats wrong with it. The script error finder on roblox didnt help me.
In Animations theres a thing called priorities. They are used to bypass or not bypass current animations. Use code below, We are going to be using action priority because its the recommended one for animations!
local seat = script.Parent function SeatIsSatIn(hit) if hit.Parent:FindFirstChild("Humanoid") then local character = hit.Parent local humanoid = character.Humanoid wait(0.5) if humanoid:GetState() == Enum.HumanoidStateType.Seated then local animation = Instance.new("Animation") animation.AnimationId = "http://www.roblox.com/asset/?id=182435998" animation.Priority = Enum.AnimationPriority.Action local track = humanoid:LoadAnimation(animation) track:Play() local function StateChanged(oldState, newState) if newState ~= Enum.HumanoidStateType.Seated then track:Stop() end end humanoid.StateChanged:connect(StateChanged) end end end seat.Touched:connect(SeatIsSatIn)