So, radius is a brick that represents the area of effect, and I wanted it so that anyone touching radius gets an attack decrease of -0.2 ONCE. This is what i came up with
radius.Touched:connect(function(hit) local attack = hit.Parent:WaitForChild("Attack") attack.Value = attack.Value - 0.2 end)
The problem is, the attack.Value - 0.2 just gets spammed by anyone moving within the radius. Is there a way so that each time someone touches the radius, the attack.Value-0.2 occurs only once, and not just spammed? ty for the help in advance
When you create an event, it returns a Connection userdata
one of the methods this disconnect
local connection connection = radius.Touched:connect(function(hit) local attack = hit.Parent:WaitForChild("Attack") attack.Value = attack.Value - 0.2 connection:disconnect() end)
Of course, this disconnects the event and it will not trigger again.
Another idea is debounce
wiki provides a better explanation, here is an example
local deb = false radius.Touched:connect(function(hit) if (deb) then return end deb = true local attack = hit.Parent:WaitForChild("Attack") attack.Value = attack.Value - 0.2 wait(2) deb = false end)