Scripting Support Neded For GUI

Hey, lately I made this code, but it doesn’t work it meant to be a button which launches a emote.
Code:
"local btn = script.Parent
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild(“Humanoid”,10)
local CanEmote = true
local CoolDown = 0

btn.MouseButton1Click:connect(function()
if CanEmote == true then
CanEmote = true
local dance = hum:LoadAnimation(script:FindFirstChild(“Anim1”))
dance:Play()

end

end)"
Please help and tell me how I can fix.

2 Likes

Please describe the problem better. Put the code in code blox and tell us exactly what the issue/error is.

2 Likes

So I had made this code for night club:
local btn = script.Parent
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild(“Humanoid”,10)
local CanEmote = true
local CoolDown = 0

btn.MouseButton1Click:connect(function()
if CanEmote == true then
CanEmote = true
local dance = hum:LoadAnimation(script:FindFirstChild(“Anim1”))
dance:Play()

end

end)
As it lauches dances, but it doesn’t work actually.

1 Like

Make sure the animation id you are using is owned by you.

Sure, thanks for the reply, it is, also thank you for helping I will try now.

Sadly it doesn’t work. Can someone help?

Hello there, here is the right code!

local btn = script.Parent
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild(“Humanoid”,10)
local CanEmote = true
local CoolDown = 0

btn.MouseButton1Click:connect(function()
if CanEmote == true then
CanEmote = true
local dance = hum:LoadAnimation(script:FindFirstChild(“Anim1”))
dance.Priority=Enum.AnimationPriority.Action
dance:Play()
end
end)

I hope that worked!

1 Like

I’m not sure this is on topic, but a snippet in your code is

if CanEmote == true then
CanEmote = true

I was wondering why the script is setting CanEmote to true after it is already set to true.
Also, if the cooldown isn’t working, you could try this:

btn.MouseButton1Down:Connect(function()
    if CanEmote then
        CanEmote = false
        local Dance = hum:LoadAnimation(script.Anim1)
        Dance.Priority = Enum.AnimationPriority.Action
        Dance:Play()
        wait(Dance.Length) -- will wait until the animation finishes playing
        CanEmote = true -- The player can use the emote again after it has done playing
    end
end)
1 Like

Sadly they do not work. Thanks for advice trough.

Make sure you’re using a localscript and the localscript is inside of a button

Are there any errors in the output?

This ie not helpful. For us to help you (which you want) you have to help us. What is the problem? Are there any errors? What is your current code? What is your goal?

1 Like

Seeing as the CanEmote is not being set to false, I see one issue.
You aren’t able to stop the debounce.

local btn = script.Parent
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild(“Humanoid”, 1)
local CanEmote = true

btn.Activated:Connect(function()
    if CanEmote then
        CanEmote = false
        local dance = hum:LoadAnimation(script:FindFirstChild(“Anim1”))
        dance:Play()
        dance.Stopped:Wait()
        CanEmote = true
    end
end)

Hopefully this solves your issue.
Also, please use ``` so your text is formatted in code.

Alrightly, so I a trying to make animation GUI, like when there is a click on it, you should start the emote. Yes there is a error, here:
Players.teddyHV11.PlayerGui.ScreenGui.Dances.Wave.LocalScript:4: unescpected symbol near ' '

Would be helpful to provide code so we can help you debug your code.

1 Like

I had saw my error, the animations weren’t public.

i mean your doing it right

local btn = script.Parent
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild(“Humanoid”,10)
local CanEmote = true
local CoolDown = 0
local dance = hum:LoadAnimation(script:FindFirstChild(“Anim1”))


btn.MouseButton1Click:connect(function()
  if CanEmote == true then
     wait(dance.length)
       dance:Stop()
end)

Hope i helped! @teddyHV11 , make sure this is a local script inside button

connect is deprecated, use Connect instead. The script itself won’t work as line 11 if else statement doesn’t have a end to it, and you never actually play the animation in that script. And the line 11 statement is useless as the debounce is never used. Sorry if this comes off as attacking! I won’t provide the correct code here as here is already the correct code and the question is solved.