Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I made a custom sitting animation seat but I have a problem. Help?

Asked by 4 years ago

Okay, So basically I made a chair model, with a seat, inside the seat is a script, and inside the script is a animation.

So the script is

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
    hit.Parent.Humanoid.Seated:Connect(function()
        local animationtoplay = hit.Parent.Humanoid:LoadAnimation(script.Animation)
        animationtoplay:Play()
        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
        while wait() do
            if Player.Character.Humanoid.SeatPart == nil then
                animationtoplay:Stop()
        print("made by yealetfng please dont steal")
            end
            end
        end)
    end
end)

it all works yet whenever you go to a different seat it wont play that animation in that seat it will play the animation of the seat you first sat in.

if anyone can help me with this would be greatly appreciated!

0
does the other seat have a different animation script? alivemaeonman 14 — 4y
0
yes each seat has a different animation ID in it yealetFNG 4 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

The problem here is that once a seat is touched the Humanoid.Seated connection in it persists, it has not been disconnected and will fire for other seats as well. You can fix this by disconnecting the event right after its first run:


script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local connection connection = hit.Parent.Humanoid.Seated:Connect(function() local animationtoplay = hit.Parent.Humanoid:LoadAnimation(script.Animation) animationtoplay:Play() local Player = game.Players:GetPlayerFromCharacter(hit.Parent) while wait() do if Player.Character.Humanoid.SeatPart == nil then animationtoplay:Stop() print("made by yealetfng please dont steal") connection:Disconnect() end end end) end end)

Another way to tackle this is to simply adjust the animation according to the seat sat on from within the connection, in a manner that you don’t have to place individual scripts, all you have to do is place the animation directly under the respective seats:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local humanoid = character:WaitForChild("Humanoid", 3)
        humanoid.Seated:Connect(function(sat, seat)
            if sat then
                 local animation = humanoid:LoadAnimation(seat.Animation)
                 animation:Play()
            end
        end)
    end)
end)
Ad

Answer this question