I am making a custom player list for my game. I don’t know why, but it won’t work. I once saw a person make a player list using only a local script, which I don’t get because I tried to use a local script. It didn’t work. I went on the dev forums, and people suggested to use a regular script. I tried that, but it still didn’t work! Here is my script:
If you have any errors, post them - it makes it easier for us to help fix the issue. I presume that the issue may be that the gui objects aren’t fully loaded upon joining, so you should use WaitForChild
Try using a LocalScript, also, how do you know it doesn’t clone? Can you take a screenshot of the explorer while in test mode? I also would like to see what the children of the “Template”.
You should try using variables more often and correctly, so that it’s easier to index instances, try using the :WaitForChild() function when you’re not sure an instance will have instantiated before you try to reference it.
Also, regular scripts do not work in Guis, if you have FE because Starter Gui places the GUI locally, whatever is in Starter Gui goes to the PlayerGui but does not replicate back to the Server, so the Server Script can’t run if the Server isn’t aware of it’s existence.
Since relatively recently, you do have the ability to access the .PlayerAdded event through Local Scripts.
When working on client sided elements you should always use LocalScripts as scrips are meant to be used primarily on the server. All Gui work should be handled in a LocalScript on the client.
When using the PlayerAdded event on the client it wont fire when your client joins the game as by the time the LocalScript runs you have already joined the game. However when other players join the game after your client has loaded the PlayerAdded event will still fire as normal.
As a possible fix you could create a function to fire each time the player joins the game and run the function when the script runs. See the edited version of your script below to see what I am on about:
local PlayersService = game:GetService("Players")
local function addSlot(player) -- function to add a slot to the player list
local slot = script.Parent.Frame.Game.Sidebar.PlayerList.Template:Clone()
slot.Parent = script.Parent.Frame.Game.Sidebar.PlayerList.Slots
slot.Name = player.Name
slot.Username.Text = player.Name
slot.Icon.Image = game.Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
end
PlayersService.PlayerAdded:Connect(addSlot) -- Fires when other players join the game
addSlot() -- Fires when your client joins the game
I am assuming you want to add all the other players to the list when you join the game. You can do this by adding a for loop to iterate through the array :GetPlayers() retruns and fire the function in the previous script. See the script below:
local PlayersService = game:GetService("Players")
local function addSlot(player) -- function to add a slot to the player list
local slot = script.Parent.Frame.Game.Sidebar.PlayerList.Template:Clone()
slot.Parent = script.Parent.Frame.Game.Sidebar.PlayerList.Slots
slot.Name = player.Name
slot.Username.Text = player.Name
slot.Icon.Image = game.Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
end
PlayersService.PlayerAdded:Connect(addSlot)
for _, player in ipairs(PlayersService:GetPlayers()) do -- Loops through the table GetPlayers() returns
addSlot(player) -- Fires the addPlayer function to add the player to the player list
end