yellow!
All I would want is to Know How to get a players screengui from a script in serverscriptservice.
Thanks!
if you already have a player variable, you could do player.PlayerGui
if you didn’t get what @HappyC0der meant… here’s the code
game.Players.PlayerAdded:Connect(function(Player)
if Player:FindFirstChild("PlayerGui") then
print("I found "..Player.Name.."'s GUI folder!")
end
end)
You can’t call PlayerGui from a Server Script. It has to be in a Local Script.
If you try to use it in a Server Script, it will return an error.
You can call player gui in a serverscript (as long as you have a player variable)
example (in one of my scripts):
for i, Player in pairs(game.Players:GetPlayers()) do
Player.PlayerGui.Ranking.Background.Visible = false
end
Hm. I thought PlayerGui was client sided.
maybe you were thinking of grabbing the player locally on a serverscript, like local player = game.Players.LocalPlayer
?
That’s what I’m saying. I thought PlayerGui was Clientsided, meaning you could only call it with Local Player.
I was right in a way.
I just looked at Studio, and then if you try to use player.PlayerGui, it gets interpreted as StarterGui.
what do you mean by that?
It’s like starter gui, but it’s for the player, and if you change the startergui contents, like setting a frame’s visibility to false, it won’t show to the player. (from my experience)
also, I knew you thought the playergui was clientsided, I just didn’t know if you got mixed up with the other thing or not
uhm… i managed to create a gui and edit its descendants’ properties… and count how many screenGuis are there… using a script in serverscriptservice…
local Count = 0
game.Players.PlayerAdded:Connect(function(Player)
if Player:FindFirstChild("PlayerGui") then
local NewGUI = Instance.new("ScreenGui")
NewGUI.Parent = Player.PlayerGui
NewGUI.Name = "Park"
local NewFrame = Instance.new("Frame")
NewFrame.Parent = NewGUI
NewFrame.Size = UDim2.new(1, 0, 0.25, 0)
NewFrame.Position = UDim2.new(0.5, 0, 0.5, 0)
NewFrame.AnchorPoint = Vector2.new(0.5, 0.5)
NewFrame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
NewFrame.Transparency = 0.25
NewFrame.BorderSizePixel = 0
end
end)
task.wait(5)
for _, v in pairs(game:GetService("Players"):GetDescendants()) do
if v.Name == "Park" then
print("I found Park!")
local NewTextLabel = Instance.new("TextLabel")
NewTextLabel.Parent = v.Frame
NewTextLabel.TextScaled = true
NewTextLabel.BackgroundTransparency = 1
NewTextLabel.Size = UDim2.new(1, 0, 1, 0)
NewTextLabel.Text = "you found me!"
end
if v:IsA("ScreenGui") then
Count = Count + 1
end
end
task.wait(1)
print("There are "..Count.." GUIS!")
Ho - Lee, (I missed so much action)
Question, would it work if I put it in something like this?
local function GuiChange(Player)
Im asking bc I need the player variable in a function like that.
Hello!
If your user interface was added into the PlayerGui
from the Client
such as a local script then it’s impossible to obtain it from the server (along with all it’s properties) as on the server it doesn’t exist.
If you want to check if a UI is on the client from the server (that’s been added by the client) I advise you use remote functions.
An example path would be this:
Send a request from the server to a remote function with the UI name as a parameter
Receive the same request on the client and then return true or false if the UI is in PlayerGui
SERVER:
local RemoteFunction = RemoteFunction
local Request = RemoteFunction:InvokeClient(Player, "UIName")
if Request then
print("Woo hoo, server got a true return")
end
CLIENT:
local RemoteFunction = RemoteFunction
RemoteFunction.OnClientInvoke = function(UIName: string)
if Player.PlayerGui:FindFirstChild(UIName, true) then
return true
else
return false
end
end
Else, your only option is to add the UI via the server in the first place.
Hope this helps!
local function GuiChange(Player)
for _, PlayerGui in pairs(Player:GetDescendants()) do
if PlayerGui.ClassName == "PlayerGui" then
-- your stuff here
end
end
end
i advise that you use @dayflare’s method as it is better
This is not necessary. All you need to do is
local playerUI = Player:WaitForChild('PlayerGui')
Even so as the PlayerGui is a core folder and a core property of the player, there will hardly exist a time where the PlayerGui folder isn’t really there.
So an even more sufficient route of doing this would be:
Player.PlayerGui
The only exceptions really being if the player is leaving or spawning in, and even so, it shouldn’t matter on local scripts as the run time should match with the players load time.
Ok I got the playergui, but it says it doesn’t know PlayerGui.ShopGui
should I have done PlayerGui:FindFirstChild("ShopGui")
Gimme Help
Maybe you’re calling it before it’s loaded, try doing player.PlayerGui:WaitForChild("ShopGui",1)
holdup, I’m getting a text in the output
ServerScriptService.GameScript:53: attempt to index nil with 'PlayerGui'