Gui = Instance.new("ScreenGui",game.Players.LocalPlayer.PlayerGui) basically doing that ^ but in a global script, I don't know any other way to put it in the LocalPlayer's playergui
Using GetPlayerFromCharacter? You would only need that if you had the character and needed the player. You didn't specify, but I'm going to assume you want to give people the GUI when they touch a part. If not, this information should still help you.
There are a few ways to do this. I'll be using Anonymous Functions
. This script assumes the script is in the desired part.
script.Parent.Touched:connect(function(p) -- Code Later end)
Now we can use the GetPlayerFromCharacter
function. If the parameters given aren't a character, the function will return nil
. We can use an conditional statement to check for this.
script.Parent.Touched:connect(function(p) local plr = game.Players:GetPlayerFromCharacter(p.Parent) if plr then -- If plr doesn't equal nil -- Code Later end end)
Script, even with FE enabled, can give player's GUIs. They can't access GUIs in the PlayerGui
however, unless the script made it.
script.Parent.Touched:connect(function(p) local plr = game.Players:GetPlayerFromCharacter(p.Parent) if plr then -- If plr doesn't equal nil local PGUI = plr:FindFirstChild("PlayerGui") local Gui = Instance.new("ScreenGui",PGUI) end end)
Good Luck!