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

Touched event if firing twice? When I Put a bool value to only fire once?

So basically the AoeSphere is a part in workspace that if you touch you only get damaged once but heres my script the problem is i am getting damaged not once but twice does anyone know whats wrong with the script I put wait(99) also this all happens under 6 seconds or so no I did not wait(99) seconds to get damaged again also I have a game.Debris:addItem in another line so thats impossible does anyone have a solution

debounce = false

AoeSphere.Touched:Connect(function(touch)
if debounce == true then return end

if debounce == false then

Hum = touch.Parent:FindFirstChild('Humanoid')

if Hum then

Hum:TakeDamage(20)

debounce = true

wait(99)

debounce = false

end

end

end)

1 comment

1

It's likely because the debounce change is after the damage is dealt. It should be before it is dealt.

1 answer

Hi i used your script in roblox studio it worked fine and it only damaged me once

debounce=false
AoeSphere=game.Workspace.AoeSphere
AoeSphere.Touched:Connect(function(touch)
if debounce==true then return end
if debounce==false then
 local Hum=touch.Parent:FindFirstChild("Humanoid")
 if Hum then
 Hum:TakeDamage(20) 
 debounce=true
 wait(99) 
 debounce=false
 end
 end
 end) 

Maybe something else is affecting it make another server script and put this code inside of it. Sry for bad english

1 comment

0

Have you tried staying on the part? Because that's where the damage is repeating.

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