I've had this problem before, yet I don't remember how to solve it and I can't find my question on how to do this, so could someone please help with my minor issue again?
Info: Server Script inside of a brick
When the brick is touched, it is supposed to give the Gui every 2 seconds (because of debounce) to any player that touches it. Yet it only gives it out the first time and I think because it keeps thinking that it is still inside the PlayerGui.
Maybe I have to make the GUI "false"? Not sure but here
local debounce = true
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not debounce then
return
end
debounce = false
if not player.PlayerGui:FindFirstChild("ShopGui") then
print("touched")
local user = game.Players:GetPlayerFromCharacter(hit.Parent)
local PG = user:WaitForChild("PlayerGui",1)
script.Parent.ShopGui:Clone().Parent = PG
wait(2)
debounce = true
else
print("player already has a shop gui")
wait(1)
debounce = true
end
end
end)

7 comments
Why would it not still be in the PlayerGui? Do you have another script removing it? Perhaps consider replacing it in the else conditional on line 18 if it still exists?
For some reason you get the player twice so you could remove the one on line 05. You also don't need to wait for the playergui so user.PlayerGui is fine (You should change user variable to player).
Is the first gui that gets added to the player ever destroyed? It should be destroyed on the server since the server had created it.
Just for future reference, if you are wondering if you've asked this before, you can go to your reputation page and see every question you've ever asked.
I know I can go there but I have asked so many questions before that I dont know for sure which one
And yes there is a button to exit and delete the GUI so it is getting deleted out of PlayerGui SO thats why Im not sure why this says the GUI is still valid
This is a server script, so it won't see changes made in local script. Destroy the one in the player and replace it on line 18