Touch Event not happening again

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?

maybe go away first and Touch it again

Nope, I tried it.

Im pretty sure it is happening because of the “if” and when the player does have the GUI and they touch it while still having it, it breaks.

What is button exactly? Is it a GUIButton, part, etc?

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

1 Like