I want to keep track of players who join my game, and more specifically who is joining multiple times (For now just a list that logs each player). I have been cruising the wiki in search of a way to do this, but I can't find anything apart from a page on saving player stats (Which isn't what I really want).
This is much more complex than anything I have tried, but i've decided I want to learn how. I don't necessarily want an example script (It would be helpful, but it would be cool to learn for myself.)
A wiki link or youtube video link will suffice, I am just lost on where to look.
I know how i can get the players name from when they join and such, but I mostly want to know how I can save and view this list of all players.
This should work really well: Google Analytics, the part about Adding your own events is probably of interest to you.
Plus with Google Analytics you get nice charts and graphs!
What you are looking for is DataStores.
DataStores act like a giant table consisting of keys and values saved for the server(or game place). You may save any and all data you want with the exception of instances.
So, lets start with how you would set your datastores up.
GetDataStore
function of DataStoreService will allow you to setup a new datastore. This takes in a string as an argument. If the string is changed, you will have a different DataStore.local ds = game:GetService("DataStoreService"):GetDataStore("PlayersEntered");
SetAsync
function to assign a value to a key inside your datastores. This value can be retrieved later by the provided key, using GetAsync
.Using the PlayerRemoving
event, you can check if the player that is leaving has any data stored already. If not, save a value of 1 to their UserId. This will identify the data as theirs. If there is data stored already, simply increment it and save it again.
game.Players.PlayerRemoving:connect(function(plr) --When the player leaves local data = ds:GetAsync(plr.UserId) --Check for saved data if data then --If there is data local new = data + 1; --Increment it. ds:SetAsync(plr.UserId,new); --Save the incremented value print(plr.Name.." has joined "..new.." times!"); else --If there isn't data ds:SetAsync(plr.UserId,1) --Save '1' for the 1st join. print(plr.Name.." joined the server once"); end end)
Note: You may also use the IncrementAsync
function for this, since all your values are going to be integers. This would look like;
ds:IncrementAsync(plr.UserId,1);
Hope I helped! And happy developing!