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)

1 comment
Thank you so much! At first it wasn't working but I added a delay to allow the player to sit down. I really appreciate the answer, thank you!