Hello I have this pretty simple carousel style GUI with 2 buttons which can be used to navigate though a number of animations. Animations are played as soon as the buttons are pressed, Additionally there is another button which resets or stops the current animation using the currentTrack
variable.
This is the script I have so far, and it works in some cases but in most cases like when I try to spam click or abuse with it, it gets lost and it doesnt stop the animation.
local Animations = game:GetService("ReplicatedFirst"):FindFirstChild("Animations", true):GetChildren() local currentIndex = script.Parent:FindFirstChild("currentIndex") local currentAnim = script.Parent:FindFirstChild("currentAnim") local currentTrack local After = script.Parent:FindFirstChild("After") local Before = script.Parent:FindFirstChild("Before") local Reset = script.Parent while not game:GetService("Players").LocalPlayer do game:GetService("Players").Changed:Wait() end local Player = game:GetService("Players").LocalPlayer while not Player.Character do Player.CharacterAdded:Wait() end local Char = Player.Character while not Char:FindFirstChildOfClass'Humanoid' do Char.ChildAdded:Wait() end local Hum = Char.Humanoid local debounce = false After.MouseButton1Click:Connect(function() if not debounce then debounce = true if Animations[currentIndex.Value + 1] then currentIndex.Value = currentIndex.Value + 1 local animId = Animations[currentIndex.Value] if not animId then print("OMG NOOOO") end if animId then local Anim = Char:FindFirstChild("DanceAnim") if not Anim then Anim = Instance.new("Animation", Char) Anim.Name = "DanceAnim" end Anim.AnimationId = "rbxassetid://"..animId.Value currentTrack = Hum:LoadAnimation(Anim) currentTrack:Play() currentAnim.Value = animId.Name end end debounce = false end end) Before.MouseButton1Click:Connect(function() if not debounce then debounce = true if Animations[currentIndex.Value - 1] then currentIndex.Value = currentIndex.Value - 1 local animId = Animations[currentIndex.Value] if not animId then print("OMG NOOOO") end if animId then local Anim = Char:FindFirstChild("DanceAnim") if not Anim then Anim = Instance.new("Animation", Char) Anim.Name = "DanceAnim" end Anim.AnimationId = "rbxassetid://"..animId.Value currentTrack = Hum:LoadAnimation(Anim) currentTrack:Play() currentAnim.Value = animId.Name end end debounce = false end end) Reset.MouseButton1Click:Connect(function() if currentTrack ~= nil then currentTrack:Stop() currentTrack = nil currentAnim.Value = '' currentIndex.Value = 0 end end)