Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[Unsolved] Why does PlayerAdded not work properly here?

Players.PlayerAdded:Connect(function(plr)
	table.insert(PlayerIndexes,plr)
	game.ReplicatedStorage.Remotes.DisplayName:FireAllClients(FindIndex(plr),plr.Name)
end)

This Code basically adds a player who joined inside a custom leaderboard inside every player. When I start a local Server, the first player can see everybody on the leaderboard, the second can see almost everybody, with one player missing. The third player can see almost every player with 2 missing. The fourth player can see almost everybody with 3 missing The fifth player... I think you get the idea. So, Question 1: Is it only a local problem or does it happen in a real game?

Question2: If it is also a problem ingame, how do I solve it?

Thanks in advance!

2 comments

0

You don’t include a player parameter with fire all clients

1

^ He most likely uses the parameter for something else, rather than telling which client to fire, since it is a custom leaderboard scrpt

2 answers

You don't need a server script for this, you can just loop through all players in the LocalScript. So, you could have a script that loops through all players and displays them on the leaderboard every time a player joins or leaves.

Something like this:

local players = game:GetService('Players')
function UpdateList()
	-- clear list
	--do something with the localplayer's name and create a frame idk
	for _,plr in ipairs(players:GetPlayers()) do
		-- do something with the player's name and create a frame idk
	end
end

players.PlayerAdded:Connect(UpdateList)
players.PlayerRemoving:Connect(UpdateList)

2 comments

0

Will the playeradded also work for the local player?

0

I just thought about that and it won't i'll add it right now

I changed your code a little


Players.ChildAdded:Connect(function(plr)
    PlayerIndexes[#PlayerIndexes + 1] = plr
    game.ReplicatedStorage.Remotes.DisplayName:FireAllClients(FindIndex(plr),plr.Name)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.