Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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
It's likely because the debounce change is after the damage is dealt. It should be before it is dealt. DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

0
Have you tried staying on the part? Because that's where the damage is repeating. DeceptiveCaster 3761 — 5y
Ad

Answer this question