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

Is there a way to have a live update of new players to your game?

I was wondering if there was a way to detect/fire a script every time a new player joins your game. Essentially, I am hoping for a live counter that will detect new users and it doesn't matter what server you are in. Please let me know.

1 answer

There is a function built into players called PlayerAdded, what it does is exactly what it says it does, it senses for new players joining. The way you could use this for a player count is put a value in ServerStorage and put the code below in a script inside ServerScriptService:

game.Players.PlayerAdded:Connect(function() -- Firing every time a player joins
	game.ServerStorage.ValueName.Value = game.ServerStorage.ValueName.Value + 1
	
	--This math makes the value one more than what it was before.

end)

The only problem with just having that is that if a player leaves and joins again, it will keep going up but never down. Thats why there is a function called PlayerRemoving which senses the exact opposite of PlayerAdded. The way you could get a value to go down with this is by putting these lines into the same script we already made (after the "end)").

game.Players.PlayerRemoving:Connect(function() -- Firing every time a player leaves
	game.ServerStorage.ValueName.Value = game.ServerStorage.ValueName.Value - 1

	--This math makes the value one more than what it was before.

end)

Hope I helped.

-Cmgtotalyawesome

3 comments

0

Thanks, but maybe I wasn't clear. I was wondering if there was a way to count players who joined the game itself and display that number throughout all servers.

0

Oh lol, I've got no idea on that, sorry

0

Try using a module script, i heard something about them being able to be called thru places

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