So, I am making a RPG game and I am working on a shop GUI, and the GUI giver breaks.
First time when I touch the GUI Giver, it gives the the GUI, but after I close it and try to use it again, it breaks. No errors in Output, this thing happened to me multiple times when doing the Touch Event
local button = script.Parent
function Touch(part)
local parent = part.Parent
if game.Players:GetPlayerFromCharacter(parent) then
local player = game.Players:FindFirstChild(parent.Name)
if not player.PlayerGui:FindFirstChild(script.Parent.Shop1.Name) then
local guiClone = script.Parent.Shop1:Clone()
guiClone.Parent = player.PlayerGui
end
end
end
button.Touched:connect(Touch)
I have no clue why it doesn’t work, does anyone know why?
there are no problems at touch script ,Our error happens while closing the gui , if you close the gui from the local script , that gui will still be visible to you in the server section , since the touched script is a normal script and you control it from the server , it cannot see it . You should use remote event and destroy the gui from the server, the script will run smoothly.
and it stucks on the “if”
hope this helps