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!
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)