Script works in studio, not in-game
The script animates a person who is sitting on a seat. It only works when I play-test through studio but not through the actual ROBLOX website. The code is in a Script not a LocalScript
I am not very good at scripting so I would really appreciate if you could tell me where to fix my code.
local seat = script.Parent function SeatIsSatIn(hit) if hit.Parent:FindFirstChild("Humanoid") then local character = hit.Parent local humanoid = character.Humanoid wait(0.5) -- Wait for character to sit if humanoid:GetState() == Enum.HumanoidStateType.Seated then -- Making sure the humanoid is sitting local animation = Instance.new("Animation") animation.AnimationId = "http://www.roblox.com/asset/?id=1336275596" -- AnimationID here 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)
You could try something like this instead:
local seat = script.Parent seat:GetPropertyChangedSignal("Occupant"):Connect(function() if not seat.Occupant then return end local anim = Instance.new("Animation") anim.AnimationId = "http://www.roblox.com/asset/?id=1336275596" local track = seat.Occupant:LoadAnimation(anim) track.Priority = Enum.AnimationPriority.Action track:Play() seat:GetPropertyChangedSignal("Occupant"):Wait() track:Stop() end)