So the past 2 days i’ve tried to make a playerlist for a game for a game. The thing is that when I test it on myself it works fine but if I test it with more people it doesn’t works.
Here’s what’s happening, the thing is that when I play it with alt accounts in the real-game it shows on one person the exact user he is but at the other it doesn’t cause by the other player it shows both users but the same profile and not the wantedlevel. And when the player is leaving it should remove the Frame from all clien’ts but that doesn’t works either.
Here’s the script:
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
local Players = game:GetService("Players")
local rep = game:GetService("ReplicatedStorage")
local playyer = Players.LocalPlayer
local uiFrameList = rep:WaitForChild("GUI"):FindFirstChild("PlayerList").Name_1
local userId = playyer.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
local uiCheck = playyer:WaitForChild("PlayerGui"):FindFirstChild("Menu").MenuFrame.PlayersFrame.ScrollPlayerList
local teamFolder = playyer:WaitForChild("TeamFolder")
local WantedFolder = playyer:WaitForChild("WantedFolder")
local wantedValue = WantedFolder.WantedLevel.Value
local frame = script.Parent
function clear()
for i, v in pairs(frame:GetChildren()) do
if v.Name == playyer.Name then
v:Destroy()
end
end
end
function fill()
if not uiCheck:FindFirstChild(playyer.Name) then
for _, player in pairs(game.Players:GetChildren()) do
local newPlayer = uiFrameList:Clone()
newPlayer.Name = player.Name
newPlayer.Profile.Image = content
newPlayer.Playername_.Text = player.Name
newPlayer.Parent = frame
for i, v in pairs(teamFolder:GetChildren()) do
if v.Value == true then
newPlayer.Team.Text = v.Name
end
end
for i, v in pairs(WantedFolder:GetChildren()) do
uiCheck:FindFirstChild(playyer.Name).WantedLevel.Text = "Wanted Level: " .. wantedValue
end
end
else
for i, v in pairs(teamFolder:GetChildren()) do
if v.Value == true then
uiCheck:FindFirstChild(playyer.Name).Team.Text = v.Name
end
end
for i, v in pairs(WantedFolder:GetChildren()) do
uiCheck:FindFirstChild(playyer.Name).WantedLevel.Text = "Wanted Level: " .. wantedValue
end
end
end
fill()
while wait(0.5) do
fill()
end
Players.PlayerAdded:Connect(fill)
Players.PlayerRemoving:Connect(clear)
here’s something I would do. When running into problems like this, you have to find where the error happened, so try joining a game with your ALT account first, and see if it works. It may have to do with the fact that the scripts are somehow interfering with each other.
When handling this, you can either put it in starter player scripts, or serverscriptsservice where it handles all the players from there. Putting it in serverscriptsservice can increase lag, but it would be more safe, where as putting the script in StarterPlayerScripts will make the game less secure, but less laggy. The client can access the guis.
I think your problem lies in the fact that on line 8 you say local uiFrameList = rep:WaitForChild("GUI"):FindFirstChild("PlayerList").Name_1. You’re referencing a single player. I don’t know if you were originally doing that for testing, but you should have a more general approach. In a script like this, you need to program dynamic. programming more dynamically is about making every thing dynamic. Don’t make variables constant names or values (if you don’t have to) because it’s easier. Everything should be based off of the playyer variable.
Like in your clear function, I don’t have alot of context, but you start an enitre for loop, when you can just say: `frame[playyer.Name]:Destroy()
The problem isn’t the uiFrameList variable cause I clone it from ReplicatedStorage and everytime a player joins it clones the frame which is named “Name_1”. And then in the further process it renames it to the player that joined but in this case that doesn’t works for one player or the other as you can see above in the vid.
the fact that it only works for one player, means that it’s targeted towards that player only, and the fact that it’s the first player, means that it’s somehow affecting other scripts, to where if another player joined, it wouldn’t work.
I just thought of something don’t know if it will work and haven’t tried it yet, but if I make a LocalScript for each player and then when they leave/join it will send it to the ServerScriptService. And from there the server can handle the player list.
Will this work or not? And on a scole from 1/10 how much will lag will it add to the game?
I don’t know but I searched some things on how to make a playerlist and they all have it in the scrrengui with no errors or anything.
So I don’t think something is wrong where the script is or if its bothering all other scripts in side the other person’ PlayerGui. If it is true what I say then what is wrong with the code?
It’s simple. All you have to do is have a local script (like what you already have) but if you need any data, you can just request it with a remote function. Send a request to the server for the data, which could be already stored, or you could just get it on the spot (I recommend the first method) and then use it.
All the other GUIs things you can handle. Your problem is about scripts only working for one person, you should rewrite all the code and do over again.
I rewrote it but now when I test it on multiple players it will replace and place the frame with the player’s name instantly even though they are already in the server.
If you know how I can solve it that would be great.
function updateList()
local getPlayers = game.Players:GetPlayers()
local x = 1
if script.Parent:FindFirstChild("Name_1") then
for key, value in pairs(getPlayers) do
if script.Parent:FindFirstChild("Name_1") then
script.Parent:FindFirstChild("Name_1"):Destroy()
wait()
end
end
end
local position = -.07
for key, value in pairs(getPlayers) do
local uiClone = game.ReplicatedStorage.GUI.PlayerList.Name_1:Clone()
local userId = getPlayers[x].UserId
uiClone.Parent = script.Parent
uiClone.Playername_.Text = getPlayers[x].Name
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isready = game.Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
uiClone.Profile.Image = content
x = x + 1
wait(.1)
end
end
while true do
updateList()
wait(0.5)
end
Also the player’s need to be updated when they leave and join but their status like if they are wanted or not and their jobs that needs to be updated continously so how do I make it that it does update the player his status but not the player itself so it dupes itself?