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

Is there a way to access all players PlayerGui (Filtering Enabled)?!??!!

Is there a way to access all players PlayerGui (Filtering Enabled)

3 comments

0

It's basically the same thing you do without FE, but use a remote event to contact the server to add a gui to each players player gui the same way you normally would.

0

Yes unless the scripts used inside is local. Remember the filtering rules, they apply to GUIs as well.

0

IM trying it later out ok

3 answers

You can, but the downside is that the server can't mess with the client's stuff (Ex, ScreenGui, LocalScript, etc). You can, however, use remotes to counter that, by having the remote communicate with the server. (The link can be found here)

The most simple method to add any sort of content to a player, which I don't understand the need to not use the StarterGui or StarterPack services for this, is to loop through the Players service (via a for loop, and the GetPlayers function; I recommend against using GetChildren when it comes to looping through the Players service: What if there was an object that wasn't a player in it, and you tried to get the player's character?)

local CurrentPlayers = game:GetService('Players'):GetPlayers() -- Call for the service, then retrieve a table for the players in the game

for i, v in next, CurrentPlayers do -- Loop through the table
	if v:FindFirstChild('PlayerGui') then -- Check if PlayerGui is there
		local Content = ... -- wuteva
		-- Other code necessary
		Content.Parent = v.PlayerGui -- Put the stuff into the player's PlayerGui
	end
end

To note when I mentioned about having to use remotes: When you have FE (Filtering Enabled) activated, a server script can NOT mess with anything on the client's side, even if it made the stuff itself (The server script). (An example would be to go to/create a new place, make sure it was FE enabled, add Kohl's admin, say ":commands", then try scrolling: It wont work.) To do this, you'd have to use remotes for it. (Click here to go to the wiki page)

Junk mentioned, but didn't really talk about

  1. Remotes - A way to have scripts communication with one another. (Like server-to-client, and vise-versa)

  2. For Loops, but because there's two different, I'm going to list the two:

2a. Generic For

  • To put simply, it iterates through a table; However, to be wary, it doesn't go within a specific order. (Not sure what example to give)

2b. For Loop

  • Iterates/loops a number of times. (For example, for iteration = 1, 10 do would loop 10 times, then stop)
  1. GetPlayers - In a nutshell: Creates a table, then puts the players in that said table. :P (Can only be used with the Players service)

  2. Filtering Enabled/Experimental Mode - Where only things done by the client also replicates to the client, but a server can do more stuff, but can't mess with the client, unless done through a remote. (Remotes still have weaknesses if you're not careful)

  3. FindFirstChild - Iterates through an object's assets, via obj:FindFirstChild('Object'), and the first object that it found will be returned, otherwise it'll return nil. However, there's a second, optional argument to the function, which will also search through descendants. obj:FindFirstChild('Obj', true) If you don't give it the second argument, by default it'll be set to false.

I hope this helped. c;

3 comments

0

Ugh, this felt sloppy. -.- Been on the ROBLOX forums too much, I guess. :/

0

You say "a server script can NOT mess with anything on the client's side, even if it made the stuff itself", but my tests (using a local test server) show otherwise. Put a ScreenGui with a TextLabel into a PlayerGui on the server (with FE enabled) and it will show up on the client; you can still manipulate the TextLabel (on the server) and it'll keep getting updated. Good answer otherwise, +1.

0

You mean in studio? If yes, then studio will show that, but not a (online) server (at least, from my knowledge, it's not supposed to do that). >-> Otherwise, I'm surprised. 0.0 I've been living a lie then.

You can. You just need to get the players using GetChildren.

for i,p in pairs(game.Players:GetChildren()) do --for every player
	local playerGui = p.PlayerGui --get their playergui and index it into a variable
	local newGui = Instance.new("ScreenGui",playerGui) --inserting a new gui into each players gui
end

Please accept my answer if this helped!

1 comment

0

Do note that though the server can add things into each player's PlayerGui (as done in this answer), it cannot access anything else from it (ex anything copied over from StarterGui). Meanwhile a client only has access to its own PlayerGui - the PlayerGui object will appear not to exist for other players.

This should work

local Players = game:GetService("Players"):GetChildren()

for _, v in pairs(Players) do
	if v:FindFirstChild("PlayerGui") then
		local Gui 
		if Gui then
			local AllThePlayersGui = v.PlayerGui:WaitForChild(Gui)
			print(Gui.Name)
		else
			print("Gui Could not be found")
		end
	end
end

change the variable called Gui to your gui and add the code in the area where it says "if Gui then"

1 comment

0

1st, in FE, the server doesn't have access to the children of PlayerGui unless it put them there with a script. 2nd, "local Gui" means "Gui" will always be nil (I think you meant to assign v:FindFirstChild("PlayerGui") to it). 3rd, :WaitForChild(Gui) wouldn't work - instead, do: v.PlayerGui:WaitForChild("GuiName")

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