Can someone help me add a debounce to this script? I'm not really sure how to do it, but it still creates multiple parts each time you click, I tried doing it but it still creates multiple parts if you spam click, can someone help?
Discord: Unknown Intelligence#6569
tool = script.Parent
local players = game:GetService("Players")
local function StopAllAnimations()
local animations = {
anim1 = players.LocalPlayer.Character.Humanoid:LoadAnimation(tool:WaitForChild("Animation"))
}
for i,v in pairs(animations) do
print("hi")
v:Stop()
end
end
tool.Equipped:connect(function()
print("Equipped")
bool = false
if not bool then
tool.Activated:Connect(function()
bool = true
print("Clicked")
players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
animation:Play()
local spirit = Instance.new("Part")
spirit.Anchored = true
spirit.Name = "spirit"
spirit.Material = "Neon"
spirit.Parent = workspace
spirit.Size = Vector3.new(5,5,5)
spirit.Shape = "Ball"
spirit.BrickColor = BrickColor.new("Cyan")
spirit.CanCollide = false
spirit.TopSurface = "Smooth"
spirit.BottomSurface = "Smooth"
spirit.LeftSurface = "Smooth"
spirit.RightSurface = "Smooth"
spirit.FrontSurface = "Smooth"
spirit.BackSurface = "Smooth"
spirit.Position = Vector3.new(players.LocalPlayer.Character.Head.Position.X, players.LocalPlayer.Character.Head.Position.Y + 30 ,players.LocalPlayer.Character.Head.Position.Z)
wait()
for i = 1,100,1 do
wait(.1)
spirit.Size = spirit.Size + Vector3.new(.2,.2,.2)
end
bool = false
end)
end
end)
tool.Unequipped:Connect(function()
StopAllAnimations()
local spirit = game.workspace:WaitForChild("spirit")
spirit:Destroy()
local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation2)
animation:Play()
players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
end)

5 comments
JUst making sure, so it adds a new tool everytime you click, correct?
It doesn't add a new tool it's just A tool, when you have the tool equipped there is no handle or anything it's just a tool, what happens is when it's equipped and activated a part spawns above your head and increases in size, but if you spam click the part spams, I need a debaunce for that idk how to do it I tried :\
ooh, so there is supposed to be a part, but not increasing in size? sorry if i'm not understanding
No it does everything perfectly it's just if you spam click it makes MULTIPLE parts I only want it to make 1 until that part is destroyed aka a debounce but idk how to add that
Oh, okay.