How do I add a Cooldown in my script to prevent overlapping?

Yea, I have gotten an issue with my touch script ,so basically this script shows whenever you touched it but it overlaps so many times.

Example of the problem:

How do I know it overlaps?
Dies 2 Dies

Script:

for _,v in pairs(EasyL:GetChildren()) do
if v:IsA(“BasePart”) then
v.Touched:Connect(function(hit)
wait(.5)
print(“TouchedA”)
local toggled = false
if toggled == false then
toggled = true
if game.Players:GetPlayerFromCharacter(hit.Parent) then
game.ReplicatedStorage.EasyL:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent), EasyL)
end
toggled = false
else
toggled = false
end
end)
end
end

The cooldown that you’re requesting is a simple use of a debounce.

Just put local toggled outside of the function.

1 Like

You could also use ZonePlus by ForeverHD https://devforum.roblox.com/t/zoneplus-v2-construct-dynamic-zones-and-effectively-determine-players-and-parts-within-their-boundaries/1017701

It has functions that detect once a player enters a zone and only fires once, vice versa with exiting, I have used this with a lot of my projects.