Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

local animPlaying = false -- Boolean Value.

local tool = script.Parent
local anim = tool:WaitForChild("Animation")

local player = game.Players.LocalPlayer


tool.Activated:Connect(function()
	if animPlaying == false then -- You can only play the animation if the boolean is false.
		animPlaying = true -- Make the value to "true" so you can't play the animation again.
		local loadedAnim = player.Character.Humanoid:LoadAnimation(anim)
		loadedAnim:Play()

		wait(animationlength) -- Add in wait() "animationlength" (Credits to: @sayer80) or a float value how much it should wait.

		animPlaying = false -- After wait() it'll become false so you can play the animation again.
	end
end)

Hope I could help you, good day!

4 comments

0

A better solution would be wait(animationlength)

0

A better solution would be wait(animationlength)

0

Yes, wait(animationlength) works better. Thank you for writing that!

0

It works thank you so much dude! I was searching for this for lots of days!

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

local tool = script.Parent
local anim = tool:WaitForChild("Animation")
	
local player = game.Players.LocalPlayer


tool.Activated:Connect(function()
	local loadedAnim = player.Character.Humanoid:LoadAnimation(anim)
	loadedAnim:Play()
	
	
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.