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

(Solved) How do I stop people from spam clicking and making how many forcefields they want?

I'm trying to make a script where, when you click with a tool a forcefield appears and after 5 seconds it ends with a 10 second cooldown, but you're able to spam it how many times you'd like to. Can anyone help me with adding a cooldown?

local Tool = script.Parent

Tool.Activated:Connect(function()
	
	local player = Tool.Parent
	local ForceField = Instance.new('ForceField')
	ForceField.Parent = player
	
	wait(5)
	
	ForceField:Destroy()
	end)

2 answers

Let me know if this is what you were looking for

local Tool = script.Parent
local cooldown = false

Tool.Activated:Connect(function()
	if cooldown == false then
		cooldown = true
		local player = Tool.Parent
		local ForceField = Instance.new('ForceField')
		ForceField.Parent = player

		wait(5)

		ForceField:Destroy()
		
		wait(10)
		
		cooldown = false
	else
		print("cooldown")
	end
end)

2 comments

0

Thank you so much, this is exactly what I needed.

0

If this is the answer you were looking for, I would appreciate it if you marked it as the answer because it gives me reputation :)

Check if there is not already a forcefield. edit wait im dumb

local Tool = script.Parent

Tool.Activated:Connect(function()
    local player = Tool.Parent
if not player:FindFirstChild("ForceField") then
    local ForceField = Instance.new('ForceField')
    ForceField.Parent = player

    wait(5)

    ForceField:Destroy()
end
    end)


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