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

how do I access the players gui from an outside script?

Asked by 5 years ago

I know that you cant change anything in the starter gui during a game, because that wont do anything. For example, what if I want to change everyone's gui at the same time, no matter if someone respawned, joined, or anything else. Imagine I need a timer for 5 minutes that doesn't reset every time someone dies, and it stays the same for everyone. I already know how to make the timer, I just dont know how to sync it across everyone. All I need is to access everyone's gui so I can change it mid-game. Does anyone know how?

2 answers

Log in to vote
0
Answered by
St_vnC 330 Moderation Voter
5 years ago

Try looping through table :

for _,Player in pairs(game.Players:GetChildren() do
      local GUI = example:Clone() -- Put the GUI you want to clone here
      GUI.Parent = Player.PlayerGui 
end
Ad
Log in to vote
0
Answered by 5 years ago

Ok, lets try it!

First Step : First of all, we need to know what's the difference from a Script and a LocalScript! In this case we will use LocalScript.

Second Step : Second, we need to know how to get to the player. So that's the why we are using a LocalScript.

Third Step : We need to know where's is our Gui and where's the "PlayerGui" instanced! So lets make the code!

Fourth Step : Enjoy coding! You have to always like what are you doing. Play some music while you script. Or even play a game before to be relaxed.

Lets get into the code!

local player = game.Players.LocalPlayer -->Getting the player
local playerGui = player:WaitForChildren("PlayerGui")
local Gui = playerGui.ScreenGui

--[[
    Change the names like "ScreenGui" to your Gui name.
]]

for _, player in pairs(game.Players:GetChildren()) do
    local cloneGui = Gui:Clone()
    cloneGui.Parent = playerGui
end

That's all! Now you can enjoy your code!

I hope that my answer already solve your question. If it doesn then, please accept my answer, that will help me a lot!

Keep scripting!

Answer this question