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

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

Asked by 4 years ago

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

Log in to vote
2
Answered by
Prestory 1395 Moderation Voter
4 years ago
Edited 4 years ago

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)
Ad

Answer this question