Can you make ScreenGuis visible when they are parented to a part?

Hi, I have a question. I have a gui, and I want to make it so when a player touches a part, a GUI pops up asking them which plane they would like to spawn. The ScreenGUI is in the part not starter gui.
Code to enable:


function onTouched(hit)
	script.Parent.newPlanesGUI.Enabled = true
end


script.Parent.Touched:connect(onTouched)

I cannot see the GUI

You would have to use PlayerGui in order to make the ScreenGui visible to the players screen

Example (Server-Sided)

function onTouched(Hit)
	local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
	local ScreenGui = script.parent:FindFirstChild("newPlanesGUI")
	local PlayerGui = Player:WaitForChild("PlayerGui")
	
	if Player then
		ScreenGui.Parent = PlayerGui
		ScreenGui.Enabled = true
	end
end

script.Parent.Touched:Connect(onTouched) -- When the part is touched it will run the function

here is an article about PlayerGui | Roblox Creator Documentation

1 Like

@WatchDogsPlayz Alright, I gtg for now but would this be for player only or for every single player?

This would be single player only.

1 Like

Alright, cuz I am making a game where you can step on a pad, and you choose what type of plane to spawn then when you click, the plane shows up for you to claim.

local players = game:GetService("Players")

local part = script.Parent
local gui = part.ScreenGui

part.Touched:Connect(function(hit)
	local hitModel = hit:FindFirstAncestorOfClass("Model")
	if hitModel then
		local hitPlayer = players:GetPlayerFromCharacter(hitModel)
		if hitModel then
			local hitPlayerGui = hitPlayer.PlayerGui
			local currentGui = hitPlayerGui:FindFirstChild(gui.Name)
			if currentGui then
				return
			end
			
			local guiClone = gui:Clone()
			guiClone.Parent = hitPlayerGui
		end
	end
end)

Here’s a script which works for every player (I’ve tested). Additionally, the script performs a check which prevents players from receiving duplicate copies of the gui prompt.

Here’s the model file for reproduction purposes.
repro.rbxm (5.6 KB)

1 Like