I am trying to make a trash can that you can push around and I'm stuck on the idle animation. This is the code:
isPushed = script.Parent.Pushing
proximity = script.Parent.BodyAttach.ProximityPrompt
idleAnimation = script.Parent.BodyAttach.Idle
function onTrigger(player)
if isPushed.Value == false then
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animateScript = character:WaitForChild("Animate")
defaultAnim1 = animateScript.idle.Animation1.AnimationId
defaultAnim2 = animateScript.idle.Animation2.AnimationId
animateScript.idle.Animation1.AnimationId = idleAnimation.AnimationId
animateScript.idle.Animation2.AnimationId = idleAnimation.AnimationId
for i,track in pairs(animator:GetPlayingAnimationTracks()) do
track:Stop(0)
end
local playerTorso = player.Character:WaitForChild("UpperTorso")
M6D = Instance.new("Motor6D", playerTorso)
M6D.Name = "TrashGrip"
playerTorso.TrashGrip.Part0 = playerTorso
playerTorso.TrashGrip.Part1 = script.Parent.BodyAttach
proximity.Style = Enum.ProximityPromptStyle.Custom
isPushed.Value = true
else
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animateScript = character:WaitForChild("Animate")
animateScript.idle.Animation1.AnimationId = defaultAnim1
animateScript.idle.Animation2.AnimationId = defaultAnim2
for i,track in pairs(animator:GetPlayingAnimationTracks()) do
track:Stop(0)
end
M6D:Destroy()
M6D = nil
proximity.Style = Enum.ProximityPromptStyle.Default
isPushed.Value = false
end
end
proximity.Triggered:Connect(function(player)
onTrigger(player)
end)
As you can see there is a loop in both cases that should stop all animations that are playing. But it doesn't stop the idle animation and it only changes if the character moves and becomes idle again.

1 comment
I tried that, but it didn't change anything. Also :Stop() and :Stop(0) should theoretically do the same thing.