Roblox Studio freeze while spamming a button

Hi,

I have this problem when I spam a button, Roblox Studio freeze and after a few seconds it’s all back. I have a debounce on the button. The debouncing is working. When I press the button, I equip and unequip a cloned object. And I also have a timer based on tick() and when the game freeze the time goes -1:59:00. The timer is not dependent of the button. Can you help me with this problem?

The code bellow it’s just an example of my code.

local thingToClone = game.ReplicatedStorage:FindFirstChild("thingToClone")
local debouncer = false
script.Parent.cloneThing.MouseButton1Click:Connect(function()
	if debouncer == false then
		debouncer = true
		wait(1)
		thingToClone:Clone()
		thingToClone.Parent = game.Workspace.ClonedThings
		debouncer = false
	end
end)
2 Likes

Would something like this work?

local thingToClone = game.ReplicatedStorage:FindFirstChild("thingToClone")
local debouncer = false
script.Parent.cloneThing.MouseButton1Click:Connect(function()
	if debouncer == false then
		debouncer = true
		task.delay(1, function()
			thingToClone:Clone()
			thingToClone.Parent = game.Workspace.ClonedThings
			debouncer = false
		end
	end
end)

Just so you know, wait() and delay() are deprecated, so use task.wait() and task.delay() instead.

Wait or task.wait() i guess, they really deprecated Wait() and Delay() and only now i notice?

It’s not working. I also forgot to mention that I clone the thing through a remote event which may crash the game when is called constantly by spamming.

Perchance the issue lies in the fact that you are naming the thing you’re cloning and the clone of it the same name?

Example code
local thingToClone = game.ReplicatedStorage:FindFirstChild("thingToClone")
local debouncer = false
script.Parent.cloneThing.MouseButton1Click:Connect(function()
	if not debouncer then
		debouncer = true
		task.wait(1) --if the lag does get solved, this wait could be removed
		local thingIsClone = thingToClone:Clone()
		thingIsClone.Parent = game.Workspace.ClonedThings
		task.wait(1)
		debouncer = false
    else
		return print("cooldown active")
	end
end)
1 Like

I’m pretty sure they didn’t officially deprecate them, but said task.wait() and task.delay() are better, and they plan to delay wait() and delay() in the future.