Hello DevForum! I am currently having an issue with stopping a looped animation with a script, for some reason it just doesn’t wanna stop, I’ve looked through other forums and couldn’t find an answer, anyone have an idea on how i could stop the animation?
Thanks!
The Script:
local CS = game:GetService("CollectionService")
local DirtCleaned = game.ReplicatedStorage:WaitForChild("Values"):WaitForChild("DirtCleaned")
--local Broom = game.ReplicatedStorage:WaitForChild("Broom"):WaitForChild("Broom")
for i, Dirt in pairs(CS:GetTagged("Dirt")) do
local Prox = Dirt:WaitForChild("ProximityPrompt")
local Sound = Instance.new("Sound")
Sound.SoundId = "rbxassetid://17227776612"
Sound.Parent = Dirt
Sound.Volume = 1
Sound.RollOffMaxDistance = 50
Sound.RollOffMinDistance = 10
local SweepingAnim = Instance.new("Animation")
SweepingAnim.AnimationId = "rbxassetid://17295162303"
Prox.PromptButtonHoldBegan:Connect(function(Player)
local char = Player.Character
local Humanoid = char:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Broom = char:FindFirstChild("Broom")
if not Broom then
warn("bro dont got the broom")
end
if Broom.Parent == char then
Sound:Play()
local SweepingTrack = Animator:LoadAnimation(SweepingAnim)
SweepingTrack:Play()
end
end)
Prox.PromptButtonHoldEnded:Connect(function(Player)
local char = Player.Character
local Humanoid = char:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Broom = char:FindFirstChild("Broom")
if not Broom then
warn("bro dont got the broom")
end
if Broom.Parent == char then
Sound:Stop()
local SweepingTrack = Animator:LoadAnimation(SweepingAnim)
if SweepingTrack.IsPlaying == true then
SweepingTrack:Stop()
SweepingTrack.Looped = false
end
end
end)
Prox.Triggered:Connect(function(Player)
local char = Player.Character
local Humanoid = char:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Broom = char:FindFirstChild("Broom")
if Sound.IsPlaying then
Sound:Stop()
end
if not Broom then
warn("bro dont got the broom")
end
if Broom.Parent == char then
Dirt:Destroy()
DirtCleaned.Value += 1
local SweepingTrack = Animator:LoadAnimation(SweepingAnim)
if SweepingTrack.IsPlaying == true then
SweepingTrack:Stop()
end
end
end)
end