Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make my animation script work in a server?

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 answer

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)

1 comment

0

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.