Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How could I create a ScreenGui in the LocalPlayer's PlayerGui using GetPlayerFromCharacter?

Asked by 8 years ago

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

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

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.


Setting up the touched event,

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)
We get p from the touched event. P represents the object that touched the part. p can be named anything, it's just a variable.

Getting the Player,

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)
plr can equal a player or nil. The if statement checks for this to make sure there's a player.

Now we give the player the GUI,

Script, even with FE enabled, can give player's GUIs. They can't access GUIs in the PlayerGuihowever, 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)
This is just an example.

Good Luck!

If I helped, please don't forget to accept my answer.
0
well, im working on a gui to test on script builder, my script has http so it cant use localscript... but then my script has localplayer so it cant be a global script... and i dont know how to set the gui in the localplayers playergui without localplayer, and without manually finding the name like this: "game.Players" etc Awsomeman511 30 — 8y
0
What? User#11440 120 — 8y
0
okay, so im making a gui through scripts so it can be used in script builder, i have a whitelist in the script that uses GetAsync on a pastebin link, that pastebin link contains a userid, it checks if the userid matches the localplayers userid, if it does, then the authorization is done, but I cant use anything with http on localscripts, so i have to use a global script, but then i cant use game.P Awsomeman511 30 — 8y
0
I really wish you said this in you question. I'm not going to answer today. Maybe ask another question, or wait for a new one here. User#11440 120 — 8y
Ad

Answer this question