Hello, I’m having trouble stopping an animation from playing inside a dummy, and then playing the one that is clicked.
Local Script:
Dance.MouseButton1Click:Connect(function()
if game.ReplicatedStorage:WaitForChild("EventPlaying").Value == false then
for i, v in pairs(workspace:WaitForChild("Player1"):GetChildren()) do
local Animation = v.Animation.AnimationId
local anim = v.Humanoid:LoadAnimation(Animation)
anim:Stop()
Animation = "rbxassetid://"..game.ReplicatedStorage:WaitForChild("Animations"):FindFirstChild("Dance").Value
anim:Play()
end
end
end
I’m not familiar with animations so it may be off.
Keep in mind, the script was working fine until I added the anim:Stop()
Any and all help is appreciated!!!
Also, an error I’m getting now is: Unable to cast value to Object, which is this line: local anim = v.Humanoid:LoadAnimation(Animation).
Sorry for the really late reply. But the value of Animation isn’t changing for some reason.
Dance.MouseButton1Click:Connect(function()
if game.ReplicatedStorage:WaitForChild("EventPlaying").Value == false then
for i, v in pairs(workspace:WaitForChild("Player1"):GetChildren()) do
local Animation = v.Animation.AnimationId
local anim = v.Humanoid:LoadAnimation(v.Animation)
anim:Stop()
Animation = "rbxassetid://"..game.ReplicatedStorage:WaitForChild("Animations"):FindFirstChild("Dance").Value
anim:Play()
end
end
end)
basically everything inside of the for loop needs to change, local Animation's value is AnimationId
you loaded the animation v.Animation to stop it Animation = ... doesn’t actually change the value of variable anim, which means anim:Play() would still be playing v.Animation
and I assume game.ReplicatedStorage.EventPlaying.Value determines if the animation is playing or not? If so you’d need to set the value to true/false each click with a elseif-then statement
local loadedAnimation --non-nested variable
Dance.MouseButton1Click:Connect(function()
if game.ReplicatedStorage:WaitForChild("EventPlaying").Value == false then
for i, v in pairs(workspace:WaitForChild("Player1"):GetChildren()) do
if loadedAnimation then
loadedAnimation:Stop() --if there's a loaded animation playing, stop it
end
v.Animation.AnimationId = "rbxassetid://"..game.ReplicatedStorage:WaitForChild("Animations"):FindFirstChild("Dance").Value -- set the new animation ID to the animation object
loadedAnimation = v.Humanoid:LoadAnimation(v.Animation) --load the new animation
loadedAnimation:Play() --play
end
end
end)