I’m trying to make a touch event where when you touch a certain part, it displays a text box gui to you. The issue is whenever I keep walking on the event part, the text keeps replaying. Does anyone know how to debounce it?
It would be
local debounce = false
function touch(hit)
if debounce = false then
debounce = true
if game.Players:findFirstChild(hit.Parent.Name) ~= nil then
Player = game.Players[hit.Parent.Name]
if Player.PlayerGui:findFirstChild("Text") == nil then
gui = script.Text:clone()
gui.Parent = Player.PlayerGui
repeat
wait()
until (Player.Character.humanoid.Position - script.Parent.Position).magnitude > 5
gui:remove()
debounce = false
end
end
end
end
local Part = script.Parent
script.Parent.Touched:connect(touch)
1 Like