This is the serverscript:
local players = game:GetService('Players')
function UpdateList()
for _,v in pairs(players:GetPlayers())--Sending to every player.
do
if v ~= nil
then
local B = game.ReplicatedStorage.Remotes.UpdateList:InvokeClient(v)--[[Invoke a function for the player.]]
repeat
wait(1)
until B == true --If the function returns true, end the waiting
end
end
end
players.PlayerAdded:Connect(UpdateList)
players.PlayerRemoving:Connect(UpdateList)
This is the local script:
players = game:GetService("Players")
TextButton = script.Parent.TextButton
game.ReplicatedStorage.Remotes.UpdateList.OnClientInvoke = function ()
for _,Button in pairs(script.Parent:WaitForChild("Frame"):GetChildren())
do
Button:Destroy()--Destroy every TextButton
end
-- Clear all Names.
for _,plr in pairs(players:GetPlayers()) do
local Clone = TextButton:Clone()--[[Clone a TextButton for every Player, with its name on it.]]
Clone.Parent = script.Parent.Frame2
Clone.Visible = true
Clone.Text = plr.Name
end
return true--returning true for the function
end
The issue is: For the first Player, it works properly. But when a second client joins in, the Textbuttons get created twice for every player on that client.

3 comments
There is no reason why you'd need a server script...
The reason is, that I can't get the players that joined before the player with the local script
the playeradded event doesnt work for them