I’m currently looking to fix this animation script, and I’m not that good with animations. It’s a seat animation, and I’m trying to make the animation load when the player sits down on the seat. I’ve been stuck on this for the past 45 minutes, and no matter what debugging I do, nothing seems to work.
Is there any way I can somehow fix this issue? It’s a script in ServerScriptService.
-- Variables
local LastOccupant
-- Code
for _,v in pairs(workspace:GetDescendants()) do
if v:IsA("Seat") and v.Name == "LongSeat" then
v.Changed:Connect(function(Property)
if Property == "Occupant" then
if v.Occupant then
local FoundOccupant = v.Occupant
local Animation = v.Animation
wait(0.1)
LoadedAnimation = FoundOccupant.Parent.Humanoid:LoadAnimation(Animation.AnimationId)
LoadedAnimation:Play()
LastOccupant = FoundOccupant
if not v.Occupant then
if LastOccupant then
LoadedAnimation:Stop()
LoadedAnimation:Remove()
end
end
end
end
end)
end
end```
Did you define the animation itself?
for example: local anim = Instance.new('Animation') anim.AnimationId = "www.roblox.com/asset/id?=" --Here You'd put the Anim ID
Okay so just an update, I was able to figure something out and it partially works. Now, the animation just randomly stops? A GIF is posted below for reference.
What you could do is be a little tricky and change the sit animation’s AnimationId from the Roblox animate script.
Here’s how the setup would be:
and here’s the script:
---------- VARIABLES ----------
local Seat = script.Parent
local Animation = Seat.SitAnim
---------- CONNECTIONS ----------
Seat:GetPropertyChangedSignal("Occupant"):Connect(function() -- if a property in the seat changes
local occupant = Seat.Occupant
if occupant then -- if we do have an occupant then do the stuff below
local character = occupant.Parent --get the character
character.Animate.sit.SitAnim.AnimationId = Animation.AnimationId --change the animation id
end
end)
Does LoadAnimation take the Id or does it take an animation instance?
Also you shouldn’t load into the humanoid. Inside the humanoid is the “Animator” which you can load it to.
Its more direct and efficient.
Also for your LoadedAnimation variable it should be a local variable since they are faster and more efficient.
-- Variables
local Occupants = {}
-- Code
for _, Seat in pairs(workspace:GetDescendants()) do
if Seat:IsA("Seat") and Seat.Name == "LongSeat" then
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if Seat.Occupant then
Occupants[Seat] = Seat.Occupant
local FoundOccupant = Seat.Occupant
local Animation = Seat.Animation
local LoadedAnimation = FoundOccupant.Parent:FindFirstChildOfClass("Humanoid"):LoadAnimation(Animation)
LoadedAnimation:Play()
else
if Occupants[Seat] then
for _, Anim in pairs(Occupants[Seat].Parent.Humanoid:GetPlayingAnimationTracks()) do
if Anim.Name == "Animation" then
Anim:Stop()
end
end
end
Occupants[Seat] = nil
end
end)
end
end
Also I edited your script if u still need it. It works now.
Another update, it wasn’t my script. It was the animator who didn’t set the animation to priority & didn’t loop it. Thank you all for the help, though!