Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Script doesn't detect PlayerGui?

I made this line of code and every time I tried to test in-game, it would spit out that PlayerGui doesn't exist, I checked and PlayerGui was there, any help? This line of code is from a module script:

function sendToAllotherPlayers(text,author) for i,plr in pairs(game.Players:GetPlayers()) do print(plr.Name,i) local plrgui = plr.PlayerGui local mod = require(plrgui:WaitForChild("ChatGui"):WaitForChild("Frame"):WaitForChild("ModuleScript")) mod.makeText(text,author) end end

2 answers

As these interfaces are client side, you will only be able to access PlayerGUI from local scripts. It only works in Studio because the solo testing doesn’t separate the server and client. Good luck!

2 comments

0

You can access it fine, just GUIs aren't replicated to the server when cloned client-side.

0

But how do I access the module script then? I mean sure local scripts can do it but it doesn't allow you to add in functions like module scripts.

Use a RemoteEvent for this, since GUIs cloned client-side (i.e. from game.StarterGui) are not replicated to the server..

Client-side you can do:

local LocalPlayer = game.Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")
local GuiName = PlayerGui:WaitForChild("GuiName")
print(GuiName.Frame)

Note that we only need to call Instance:WaitForChild() on the Player.PlayerGui itself and top-level objects inside it. After that, everything inside the GUI will already have been loaded.

2 comments

0

As for that line of code, does it access all players and not just one?

0

This would be client-side. You'd use a RemoteEvent and call RemoteEvent:FireAllClients(), and handle the remote client-side to make changes to the GUI.

This discussion is preserved as it was. New answers, comments, and votes are closed.