Hey there ars the topic says my playerlist(not the leaderstats one) doesn’t work correctly,It only shows the info for the local player(you) and not the others. I had also added a custom gradient.
Script is a script within serverscriptservice
local plrs = game.Players
local Clone = script:WaitForChild("MainFrame"):Clone()
game.Players.PlayerAdded:Connect(function(plr)
local Group = 13562934
local owner = 255
Clone.NameoFplAYER.Text = plr.Name
Clone.DisplayNameofplr.Text = "@" .. plr.DisplayName
local function ImageOfPlayer(plrid)
local thumbSize = Enum.ThumbnailSize.Size100x100
local ThumbType = Enum.ThumbnailType.HeadShot
local content,isReady = plrs:GetUserThumbnailAsync(plrid,ThumbType,thumbSize)
return content
end
if plr:GetRankInGroup(Group)== owner then
Clone.BackgroundColor = BrickColor.new("White")
Clone.UIGradient.Enabled = true
end
Clone.ImageofPlayer.Image = ImageOfPlayer(plr.UserId)
Clone.Visible = true
Clone.Parent = plr.PlayerGui:WaitForChild("PlayerList").TheMainList.ScrollingFrame
game.ReplicatedStorage.EventForPlayerList.OnServerEvent:Connect(function(plrName)
wait(1)
if plrName.PlayerGui.PlayerList.TheMainList.ScrollingFrame:WaitForChild("MainFrame") then
print("Present")
plrName.PlayerGui.PlayerList.TheMainList.ScrollingFrame:WaitForChild("MainFrame"):Destroy()
end
local clone2=script:WaitForChild("MainFrame"):Clone()
clone2:WaitForChild("NameoFplAYER").Text = plrName.Name
clone2:WaitForChild("DisplayNameofplr").Text = "@" .. plrName.DisplayName
local function ImageOfPlayer(plrid)
local thumbSize = Enum.ThumbnailSize.Size100x100
local ThumbType = Enum.ThumbnailType.HeadShot
local content,isReady = plrs:GetUserThumbnailAsync(plrName.UserId,ThumbType,thumbSize)
return content
end
if plr:GetRankInGroup(Group)== owner then
clone2.BackgroundColor = BrickColor.new("White")
clone2.UIGradient.Enabled = true
end
clone2.ImageofPlayer.Image = ImageOfPlayer(plrName.UserId)
clone2.Visible = true
clone2.Parent = plrName.PlayerGui.PlayerList.TheMainList.ScrollingFrame
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
Clone:Destroy()
end)
I don’t think you should even do this on the server. Make a loop in a localscript that is always checking for new players that clones the player info accordingly. This is what I do to make my player lists (I also use a UIGridLayout):
local Example = script.Parent:WaitForChild('Example')
local Players = game:GetService('Players')
Players.PlayerRemoving:Connect(function(plr)
if script.Parent:FindFirstChild(plr.Name) then
script.Parent:FindFirstChild(plr.Name):Destroy()
end
end)
while task.wait() do
for _, v in pairs(Players:GetChildren()) do
if not script.Parent:FindFirstChild(v.Name) then
local PlayerFrame = Example:Clone()
PlayerFrame.Name = v.Name
PlayerFrame.Parent = script.Parent
end
end
end
Yes, I’m pretty sure it’s inefficient but it’s only on the client.
Instead of the while true do loop you can have a server script listen for PlayerAdded events to fire and then have it call “:FireAllClients()” through/on a RemoteEvent instance when it does. A local script can then act as a listener for these “:FireAllClients()” calls with the “OnClientEvent” event through/on the same RemoteEvent instance. Thus we have emulated a PlayerAdded event which works locally for every client. Here’s a short example.
--SERVER
local Players = game:GetService("Players")
local Replicated = game:GetService("ReplicatedStorage")
local Remote = Replicated.RemoteEvent
Players.PlayerAdded:Connect(function(Player)
Remote:FireAllClients(Player.Name, Player.UserId)
end)
--LOCAL
local Replicated = game:GetService("ReplicatedStorage")
local Remote = Replicated:WaitForChild("RemoteEvent")
Remote.OnClientEvent:Connect(function(PlayerName, PlayerId)
print(PlayerName, PlayerId)
end)
Knew someone would reply with that. The issue is that if a player joins when a few players were already in the game, they wouldn’t exist on the player list (if i remember correctly…).
I’d actually say you should get an actual person to test it since you need to know if it updates whenever you join when there’s already existing players in the game
Yes, when a player first joins you should iterate over the existing players (but only once), I was under the impression that was already being done. It’s relatively trivial to implement that feature into my previous example.
--SERVER
local Players = game:GetService("Players")
local Replicated = game:GetService("ReplicatedStorage")
local Remote = Replicated.RemoteEvent
Players.PlayerAdded:Connect(function(Player)
Remote:FireAllClients(Player.Name, Player.UserId)
end)
--LOCAL
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Replicated = game:GetService("ReplicatedStorage")
local Remote = Replicated:WaitForChild("RemoteEvent")
Remote.OnClientEvent:Connect(function(PlayerName, PlayerId)
print(PlayerName, PlayerId)
end)
local function InitializeScript()
for _, TablePlayer in ipairs(Players:GetPlayers()) do
if TablePlayer ~= Player then
print(TablePlayer.Name, TablePlayer.UserId)
end
end
end
InitializeScript()
local Example = script:WaitForChild('MainFrame')
local Players = game:GetService('Players')
Players.PlayerRemoving:Connect(function(plr)
if script.Parent:FindFirstChild(plr.Name) then
script.Parent:FindFirstChild(plr.Name):Destroy()
end
end)
while task.wait() do
for _, v in pairs(Players:GetChildren()) do
if not script.Parent:FindFirstChild(v.Name) then
local PlayerFrame = Example:Clone()
PlayerFrame.NameoFplAYER.Text = v.Name
PlayerFrame.Name = v.Name
PlayerFrame.Visible = true
PlayerFrame.Parent = script.Parent.TheMainList.ScrollingFrame
end
end
end