I have an animation that I would like to loop when a value changes, but it doesn't loop for some reason; Here is my code:
local IsStunned = script.Parent:FindFirstChild("Stunned")
local Humanoid = script.Parent:WaitForChild("Humanoid")
local StunAnimation = workspace:WaitForChild("Stunned")
local PlayAnimation = Humanoid:LoadAnimation(StunAnimation)
local function StunPlayer()
if IsStunned.Value == true then
script.Parent.Humanoid.WalkSpeed = 0
script.Parent.Humanoid.AutoRotate = false
PlayAnimation:Play()
PlayAnimation.Looped = true
end
end
local function UnstunPlayer()
if IsStunned.Value == false then
PlayAnimation:Play()
PlayAnimation.Looped = false
script.Parent.Humanoid.WalkSpeed = 5
wait(0.2)
script.Parent.Humanoid.WalkSpeed = 16
script.Parent.Humanoid.AutoRotate = true
PlayAnimation.Looped = true
end
end
IsStunned.Changed:Connect(StunPlayer)
IsStunned.Changed:Connect(UnstunPlayer)

2 comments
Sorry, it didn't work.
Okay! Thank you for letting me know.