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)
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)
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.
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.
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.
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
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);