Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How Do I Remove The Possibility To Spam Click An Item Animation?

Asked by 4 years ago

How do i remove the possibility to spam click an item animation? I know that i have to add a debounce and other things like that but im not an expert, so i dont know how to add it!

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Hi, you can use a boolean value to control that you can't play the animation again while it's playing. I'll show you how it works.

01local animPlaying = false -- Boolean Value.
02 
03local tool = script.Parent
04local anim = tool:WaitForChild("Animation")
05 
06local player = game.Players.LocalPlayer
07 
08 
09tool.Activated:Connect(function()
10    if animPlaying == false then -- You can only play the animation if the boolean is false.
11        animPlaying = true -- Make the value to "true" so you can't play the animation again.
12        local loadedAnim = player.Character.Humanoid:LoadAnimation(anim)
13        loadedAnim:Play()
14 
15        wait(animationlength) -- Add in wait() "animationlength" (Credits to: @sayer80) or a float value how much it should wait.
16 
17        animPlaying = false -- After wait() it'll become false so you can play the animation again.
18    end
19end)

Hope I could help you, good day!

0
A better solution would be wait(animationlength) sayer80 457 — 4y
0
A better solution would be wait(animationlength) sayer80 457 — 4y
0
Yes, wait(animationlength) works better. Thank you for writing that! R4nd0ml0l2 105 — 4y
0
It works thank you so much dude! I was searching for this for lots of days! hellmet1 42 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

This is the localscript that i use to play an item animation :

01local tool = script.Parent
02local anim = tool:WaitForChild("Animation")
03 
04local player = game.Players.LocalPlayer
05 
06 
07tool.Activated:Connect(function()
08    local loadedAnim = player.Character.Humanoid:LoadAnimation(anim)
09    loadedAnim:Play()
10 
11 
12end)

Answer this question