Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Dad_Bot 34
6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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

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. Dad_Bot 34 — 6y
0
Oh lol, I've got no idea on that, sorry cmgtotalyawesome 1418 — 6y
0
Try using a module script, i heard something about them being able to be called thru places SmugNyan 24 — 6y
Ad

Answer this question