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

OnTouch script deletes the gui twice instead of the intended ammount, 1?

My script that is supposed to delete a gui once, deletes it twice, any help with this?

local GiveBack = Instance.new("RemoteEvent")
GiveBack.Parent = game.ReplicatedStorage
GiveBack.Name = "GiveLitBack"
script.Parent.Touched:connect(function (hit)
 if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then
      local plr = game.Players[hit.Parent.Name]
if plr.PlayerGui:WaitForChild("Tattoo2") then
      plr.PlayerGui:WaitForChild("Tattoo2"):Destroy()
GiveBack:FireClient(plr)
end
 end
end)

1 answer

✓ Accepted answer

You need to use a Debounce like this

local GiveBack = Instance.new("RemoteEvent")
Debounce = false
GiveBack.Parent = game.ReplicatedStorage
GiveBack.Name = "GiveLitBack"
script.Parent.Touched:connect(function (hit)
 if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) and not Debounce then
 Debounce = true
      local plr = game.Players[hit.Parent.Name]
if plr.PlayerGui:WaitForChild("Tattoo2") then
      plr.PlayerGui:WaitForChild("Tattoo2"):Destroy()
GiveBack:FireClient(plr)
wait(2)
Debounce = false

end
 end
end)

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