Answered by
Azuc 112
6 years ago
From what you asked I think you are trying to say that you want them to start from 0 each time they join but still have their overall kills for each time they have played be saved somewhere. If you are just looking for a general datastore thats fine as well this will fith both needs.
Create a folder in ReplicatedStorage called PlayerData, update whatever pvp scripts you are using to update the Kills and Deaths inside that folder alongside your current leaderstats via the hierarchy of:
1 | game.Players = game.Players.LocalPlayer |
2 | game:GetService( "ReplicatedStorage" ).PlayerData:WaitForChild(player.name).Stats |
You can then have a place in game or on a gui to display their total career stats by pulling the values from the folder referenced above. The main script below simply goes in a script in the ServerScriptService.
I added a cash line if you have a money system you would like to save as well but you can simply remove it if it is not needed as well as copying those lines for more stats you wish to create.
Don't forget to change the key on the first line as well.
01 | local DS = game:GetService( "DataStoreService" ):GetDataStore( "PUTRANDOMKEYHERE" ) |
02 | local PlayerData = game:GetService( "ReplicatedStorage" ):WaitForChild( "PlayerData" ) |
04 | game.Players.PlayerAdded:Connect( function (player) |
05 | local PlayerFolder = Instance.new( "Folder" , PlayerData) |
06 | PlayerFolder.Name = player.name |
08 | local Stats = Instance.new( "Folder" , PlayerFolder) |
11 | local Kills = Instance.new( "IntValue" , Stats) |
14 | local Deaths = Instance.new( "IntValue" , Stats) |
15 | Deaths.Name = "Deaths" |
17 | local Cash = Instance.new( "IntValue" , Stats) |
20 | local SavedData = DS:GetAsync(player.userId) |
23 | for i,v in pairs (SavedData) do |
25 | PlayerData [ player.Name ] .Stats:FindFirstChild(SavedData [ i - 1 ] ).Value = v |
31 | local function SaveValues(player) |
33 | for i,v in pairs (PlayerData [ player.name ] .Stats:GetChildren()) do |
34 | Data [ #Data + 1 ] = v.Name |
35 | Data [ #Data + 1 ] = v.Value |
37 | DS:SetAsync(player.userId, Data) |
40 | game:BindToClose( function () |
41 | for i, player in pairs (game.Players:GetPlayers()) do |
46 | game.Players.PlayerRemoving:connect( function (player) |