Hello! I am making an emote system, where when the player clicks on the GUI object the animation plays.
However, when the player presses the GUI, whatever dance animation is playing stops, but this is not working as it doesn’t stop it! It just overrides the old dance animation.
There are no errors in the output.
Can anyone help me? I would greatly appreciate it!
Thank you.
local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local hum = character:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local PlayerMod = require(plr.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerMod:GetControls()
local animations = {
["Sturdy"] = animator:LoadAnimation(plr.PlayerGui:WaitForChild("Emotes"):WaitForChild("Animations").Sturdy),
["Insanity"] = animator:LoadAnimation(plr.PlayerGui:WaitForChild("Emotes"):WaitForChild("Animations").Insanity)
}
local function stopAnims()
for _, v in ipairs(animations) do
v:Stop()
end
end
local db = false
for _, v in ipairs(script.Parent:GetChildren()) do
if v:IsA("ImageButton") then
v.MouseButton1Click:Connect(function()
if not db then
stopAnims()
local anim = table.find(animations, v.Name)
anim:Play()
Controls:Disable()
db = true
elseif db then
stopAnims()
local anim = table.find(animations, v.Name)
anim:Stop()
Controls:Enable()
db = false
end
end)
end
end