Can you get all players PlayerGui from a localscript? [CLOSED]

Im trying to make a script that if anyone in the server has a GUI then their name would pop up on a gui. script below

local ResultsFrame = script.Parent.Parent.ScrollingFrame
local Button = script.Parent
local DetectedPlayers3 = 0

Button.MouseButton1Click:Connect(function(player)
local Players = game:GetService("Players")
	for _, player in ipairs(Players:GetPlayers()) do
	local gui = player:WaitForChild("PlayerGui")
		local b = gui:WaitForChild("UIname")
		if b:WaitForChild("scriptName") then
			for _, children in ipairs(ResultsFrame:GetChildren()) do
				if children.Name == player.Name then
					children:Destroy()
				end
			end
			DetectedPlayers3 = DetectedPlayers3 + 1
			local temp = ResultsFrame.TextLabel
			local new = temp:Clone()
			new.Name = player.Name
			new.Text = player.Name
			new.Visible = true
			new.Parent = ResultsFrame
	end
	print(DetectedPlayers3)
	DetectedPlayers3 = 0
	end
end)

If anyone could help i’d appreciate it

When ran gives me PlayerGui is not a valid member of Player1 (When multiple people have the GUI and one person scans only the person who scans pops up on the list then the error appears in output)

Why not just retrieve then in a table from the server?, or does your project require it to be locally.

1 Like

Well the script is a local script and it’s under a GUI that you have to press a button and scan. If a table is possible could you provide a example?

–// Server:

local PlayerService = game:GetService('Players');
local Event = PATH_TO_EVENT;

Event.OnServerEvent:Connect(function())
local PlayerGuis = {};
for _, Player in next, PlayerService:GetPlayers() do
local PlayerGui = Player:WaitForChild('PlayerGui')
if not PlayerGui then continue end;
PlayerGui[Player.Name] = PlayerGui;
end;
return PlayerGuis;
end);

–// Client:

local Event = PATH_TO_EVENT (same event from server)

Button.MouseButton1Click:Connect(function()
local PlayerGuis = Event:FireServer();
print(PlayerGuis)
end);

Here you go, this is a rushed simplified version, but this should do the trick.

also I’d recommend that you create dedicated local functions for Event.OnServerEvent and Button.MouseButton1Click, if you feel like it xd

Example:

local OnClick = function()
print('Hello, World!')
end;

Button.MouseButton1Click:Connect(OnClick);

Also remember if my code snipper worked for you, to select if as the solution, alright I’m going back to studio hope it worked.

image
Their names is supposed to pop up in this ScrollingFrame textLabel and whenever a player has a specific UI and you click scan their name pops up. I don’t really think you got the right idea

did you just copy my script or did you actually modify if to your liking?

local PlayerGuis = PATH_TO_TABLE (from button)
for String in next, PlayerGuis do
local TextLabel = (new textbael or clone a template)
TextBabel.Name, TextLabel.Parent = String, (YOUR SCROLLFRAME);
end;

add this where ever, also print what the for i loop is returning, i forgot what :GetPlayers() returns lol i think its index and children, but i could be wrong.

I modified it myself to my liking.

The textlabel’s parent is the scroll frame so i dont get how this would work

TextLabel.Name, TextLabel.Parent = String, (YOUR SCROLLFRAME);

you have to clone said textlabel or create a new one for each player, when something it created or cloned its parent is nil so you have to set it, thats what the .Parent = YOURSCROLLFRAME is for.

So this would be the script correct?

local PlayerService = game:GetService('Players');
local Event = script.Parent:FindFirstChild("GetPlayerGui");

Event.OnServerEvent:Connect(function()
local PlayerGuis = {};
for _, Player in next, PlayerService:GetPlayers() do
	local PlayerGui = Player:WaitForChild('PlayerGui')
		for String in next, PlayerGuis do
			local TextLabel = Event.Parent.Parent:WaitForChild("ScrollingFrame"):WaitForChild("TextLabel"):Clone()
			TextLabel.Name, TextLabel.Parent = String, Event.Parent.Parent:WaitForChild("ScrollingFrame");
		end;
	end;
return PlayerGuis;
end);

I am kind of new to LuaU so this is mad confusing lol

No, erase all of that and put my original snippet back, you have to clone / create a textlable and parent it on the clicne section.

If you want i you can add me to team create and I could do it-

also is the RemoteEvent in replicatedstorage?, i see you defined it as a child of script.Parent.

The remote is under script.Parent. I keep my remotes under script.Parent sometimes.

I guess I could add you to team create I am half asleep and new to luaU(ish) lmao so just add my account “LoopedFunction”

Try this, also i added you.

local Event = PATH_TO_EVENT (same event from server)

Button.MouseButton1Click:Connect(function()
local PlayerGuis = Event:FireServer();
for String in next, PlayerGuis do
local textlabel = YOURLABEL;
textlabel.Text, textlabel.Paret = String, YOURSCROLLINGFRAME;
task.wait();
end;
end);

Didn’t work i added you to team create though.

DONE (select this as the solution if your are satisfied)