Hi there, I am having trouble with destroying a cloned GUI. There is one script that when you touch a part is clones a GUI into PlayerGui. Then there is a localscript that destroys the GUI in playergui when you click a textbutton. The Script is under the part and the localscript is under the screengui.
script
local GUI = script.Parent.Shop
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:FindFirstChild("PlayerGui") and not plr.PlayerGui:FindFirstChild(GUI.Name) then
GUI:Clone().Parent = plr.PlayerGui
end
end
end)
localscript
script.Parent.MouseButton1Click:Connect(function()
wait(1)
if script.Parent.Parent.Parent:FindFirstChild("Shop") then
game.Players.LocalPlayer.PlayerGui.Shop:Destroy()
end
end)
Thank you👍
1 Like
Maybe replacing the Script with this will help?
local GUI = script.Parent.Shop
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:FindFirstChild("PlayerGui") and not plr.PlayerGui:FindFirstChild(GUI.Name) then
local newGUI = GUI:Clone()
newGUI.Name = "Shop"
newGUI.Parent = plr.PlayerGui
end
end
end)
nope, it doesn’t work. when I click close. it closes the GUI, but when I touch the brick after I hit close. it doesn’t reappear.
I’ll take my guess at what’s happening here. As you are only deleting the GUI on the client side with a local script, it does not tell the server that you destroyed the GUI. Therefore the server still sees that you have the GUI open. You can avoid this either by a remote event to tell the server to also delete the GUI, or you can only create the GUI on client side so you don’t have to worry about telling the server whether its open or not(my recommended method). You probably will still have to end up telling the server what you click on in the shop, but that’s a later thing to worry about.
I figured out a better method for this. a proximity prompt. Thanks for all of your help
1 Like