SO I made this script where if you touch a brick with this script inside of it, a GUI pops up. For some reason multiple GUI's pop up if you continuously touch the brick. How can I prevent that? I also want to make it so when the GUI pops up you become anchored until you click exit on the GUI. How can I do this stuff?
local debounce = false
function getPlayer(humanoid)
local players = game.Players:children()
for i = 1, #players do
if players[i].Character.Humanoid == humanoid then return players[i] end
end
return nil
end
function onTouch(part)
local human = part.Parent:findFirstChild("Humanoid")
if (human ~= nil) and debounce == false then
debounce = true
local player = getPlayer(human)
if (player == nil) then return end
user = game.Players:findFirstChild(human.Parent.Name)
script.Parent.ShopGUI:clone().Parent = player.PlayerGui
wait(2)
else
wait(2)
debounce = false
end
end
script.Parent.Touched:connect(onTouch)
|