Part that would enable a GUI

Part to enable GUI

Hello readers, I have been stumbling around the roblox developer forums, youtube tutorials and models for a way to both recognize when a player has touched a part. And also use scripting inside the function of the part script to open a GUI for a player, not anything too tech savvy. Just a simple:

game.Players.LocalPlayer.PlayerGUI.-whatever-.-whatever-.visible = true
-- example, that never works

Overall:
I have not scripted for years, and I would just like a friendly reminder of how it works. Again, I have looked around everywhere and nothing seems to be working. I am also a very new scripter.

Sorry for the trouble!

You could simply use a normal script for this.

local Part = script.Parent -- reference

Part.Touched:Connect(function(PartThatTouched)
	local Model = PartThatTouched:FindFirstAncestorOfClass("Model") -- check for a model
	if Model then
		local Player = game.Players:GetPlayerFromCharacter(Model) -- if Player is not nil, the model was a character
		if Player then
			Player.PlayerGui.ScreenGui.Enabled = true -- enable the gui
			-- or
			Player.PlayerGui.ScreenGui.Frame.Visible = true -- make a frame visible
		end
	end
end)

You can achieve this in a simple way by using the Player service’s function; GetPlayerFromCharacterFunction(), however changing client properties from the server can lead to replication issues, such as the server not recognizing changes, so I would instead try to handle as much as possible on the client by using RemoteEvents.

No, this is wrong. You can edit Guis on the server.

Yes I realized that, apologies for the mistake.

Thank you so much for the help! I owe you one :wink: @Avallachi

VeRy Helpful Thanks a lot :wink: @Avallachi

-Khwandee1

You can but you shouldn’t, screen guis are player specific anyway and as such should be handled by the client (via local scripts), this is to alleviate any unnecessary strain/stress exerted on the server.