Why doesnt this custom playerlist script work?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Make a Playerlist system

  1. What is the issue? Include screenshots / videos if possible!

The cloned template doesnt show up to the list

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried using functions, using :ClearAllChildren and Putting the template in Replicated storage.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local PLayerTemp = game.ReplicatedStorage.PlayerTemplate
local NewPlayerTemp = PLayerTemp:Clone()

local function addPlayerToList()
	local plr = game.Players.LocalPlayer
		

		NewPlayerTemp.Text = plr.Name
		NewPlayerTemp.Name = plr.Name.."List"
		NewPlayerTemp.Parent = script.Parent
		NewPlayerTemp.Visible = true
		

end

local function RemovePlayerFromList()
	
	NewPlayerTemp:Destroy()

end



game.Players.PlayerAdded:Connect(addPlayerToList)
game.Players.PlayerRemoving:Connect(RemovePlayerFromList)
1 Like

I’m bad at explaining so I’ll try to send the fixed code (atleast I think it works):

local PLayerTemp = game.ReplicatedStorage.PlayerTemplate
local NewPlayerTemp = PLayerTemp:Clone()

game.Players.PlayerAdded:Connect:(function(plr)
		gPlr = plr

		NewPlayerTemp.Text = plr.Name
		NewPlayerTemp.Name = plr.Name.."List"
		NewPlayerTemp.Parent = script.Parent
		NewPlayerTemp.Visible = true
		

end


game.Players.PlayerRemoving:Connect(plr)
if plr = gPlr then
newPlayerTemp:Destroy()
end


end)



This probably dosent work :confused:

You’re cloning PlayerTemp at the start of the script, one line 2, but that only runs once. You need to create a clone for every player instead. Try

`
local PlayerTemp = game.ReplicatedStorage.PlayerTemplate

local function addPlayerToList(player)
	local plr = game.Players.LocalPlayer

        local entry = PlayerTemp:Clone()

		entry.Text = plr.Name
		entry.Name = plr.Name.."List"
		entry.Parent = script.Parent
		entry.Visible = true
end
1 Like

Hey! Make sure that is a server script (I belive playerAdded / playerRemoving doesn’t work on client) and use remote events to fire to every client to tell them to update the player list.

They still do. I have a Leaderboard script that only runs on the Client and they work

2 Likes

How would i be able to delete the template though?

oh yeah, it still didnt work by the way…

Add a

:WaitForChild()

function.
Do it like this

ReplicatedStorage:WaitForChild(“PlayerTemp”)

.

The problem might be that the script runs when the game isn’t fully loaded so when WaitForChild is called. this will wait for the object before it continues running a code

Yea… it didnt

1st of all, when is gPlr defined
2nd of all what is Connect(plr)

Could you also send what errors you get when you start the game?

thats kinda the thing… no errors at all

i could try printing (Letter Limit)

i think i found the problem with your script.

So you are trying to get each player that joins the game right?

yeah thats the idea i guess (limit)

so try changing this Variable in the function to local plr = game.Players:GetChildren()

then at the very end of the script put this code:

game.Players.PlayerAdded:connect(function(player)
addPlayerToList(player) -- This will run whenever a player joins making it update the playerlist
end)

Put the above script outside the function addPlayerToList.

Its still not working. did i edit it correctly?



local function addPlayerToList()
	local plr = game.Players.LocalPlayer
	local NewPlayerTemp = PLayerTemp:Clone()
print("ClonedTemp")
		NewPlayerTemp.Text = plr.Name
		NewPlayerTemp.Name = plr.Name.."List"
		NewPlayerTemp.Parent = script.Parent
	NewPlayerTemp.Visible = true
	print("Temp is inside list")
		

end

local function RemovePlayerFromList()


end



game.Players.PlayerAdded:Connect(function(plr)
	addPlayerToList(plr)
end)
game.Players.PlayerRemoving:Connect(RemovePlayerFromList)

end

did you change local plr = game.Players.LocalPlayer to local plr = game.Players:GetChildren()

Haha…

it still doesnt work :joy:

Decided to rescript the entire function. try this:

local function addPlayerToList(player)
	local plr = game.Players:GetPlayers()
	for i,v in pairs(plr) do
		local PlayerTemp = game.ReplicatedStorage:WaitForChild("PlayerTemp")
		local NewPlayerTemp = PlayerTemp:Clone()
		print("ClonedTemp")
		NewPlayerTemp.Text = plr.Name
		NewPlayerTemp.Name = plr.Name.."List"
		NewPlayerTemp.Parent = script.Parent
		NewPlayerTemp.Visible = true
		print("Temp is inside list")
	end
end