Won't give me the gui if I touch the part

script.Parent.Touched:Connect(function(p)
	if p.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(p.Parent)
		if not plr.PlayerGui:FindFirstChild("Elevator") then
			script.Elevator:Clone().Parent = plr.PlayerGui
		end
	end
end)

This is my current script, when I touch a part it’s supposed to give me a gui (which it does) and when that gui is deleted and I go to touch the part again, it doesn’t work. Help!

1 Like

How is the gui deleted, do you open the explorer window while playtesting and then delete the gui from there? If so the gui will no longer exist on the client but will still exist on the server. You have to make a server script destroy that gui so when the script you have checks for it it won’t exist.

There is a button on the gui that is meant to close it, I used the :Destroy() function

Is that a local script?

You need to fire an event to a local script and clone it there. Server scripts aren’t really meant for guis.

Yes, the script inside the button.

Also, touch events are only server-sided lol. It won’t work in a local script.

Alright so you’ll have to either make that script a server script (just “script”) or use a remote event.

There isa script inside of the touch part, which is a server script. I have another script inside the gui’s button which is meant to delete it.

Perhaps you are doing this:

script.Elevator:Destroy()

This deletes the GUI.

Instead, try this code:

script.Parent.Touched:Connect(function(p)
	if p.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(p.Parent)
		if not plr.PlayerGui:FindFirstChild("Elevator") then
			local clonedGui = script.Elevator:Clone()
            clonedGui.Parent = plr.PlayerGui
		end
	end
end)

And then, when you want to destroy the clone, do

clonedGui:Destroy()

I don’t know if making it a server script will work but I’ll try it out.

Touched can also be used on the client

You can use the Touched event from a local script. Put a local script in StarterPlayerScripts and then insert a part into workpsace.

game.Workspace.Part.Touched:Connect(function()
    print("hit")
end)

Anyway this is irrelevant since he’s using a server script to detect if it’s touched.

1 Like

I had a part in my simulator that made the shop gui appear you have to use a remote event because you can’t see it on the client but the server won’t know that it’s not visible
Edit:Use a remote event on any gui buttons and use a player parameter on the OnServerEvent in server script service

1 Like

I was destroying it from the gui itself, it’s fine, I’m using an event to destroy it now.