I am making a script so when a player clicks a particular part it increases variable 'progress' whilst they are within range of the part. The first script is here:
local working = false
local toolbox = script.Parent.Parent.Parent.Workspace.gen1.toolbox.detector
local clickDetector = toolbox:WaitForChild("ClickDetector")
clickDetector.MouseClick:Connect(function(Player)
while wait(1) do
local Mag = (script.Parent.toolbox.walkto.Position-Player.Character.HumanoidRootPart.Position).magnitude
if Mag >= script.Parent.Range.Value then
working = false
print("working = false")
end
if Mag <= script.Parent.Range.Value then
working = true
game.Workspace.gen1.working:Fire()
print("working = true")
end
end
end)
The script that increments the value when the event is fired is here:
local progress = 0
game.Workspace.gen1.working.Event:Connect(function()
wait(1)
progress = progress + 1
print(progress)
end)
My problem is that the player can just click click detector infinitley spamming the event to update progress by one, how can I debounce this?

5 comments
Running this code shows only working being printed to the output, meaning it isn't running when working = true
Oh you wanted a debounce for your first script? Hold on, I'll edit the reply.
Haha sorry I thought that was for the first script not the second, got variable names mixed up. Don't bother. It works fine. Thank you so much! :)
Oh well, I still did it xD. This should also work, it is up to you if you want to change it.
Thank you, I think I will use it :)