I want to save my kills so whenever a player joins back, they have the right amount of wins and loses.
In order to do what you want, you need to use DataStores.
Create your DataStore using the GetDataStore
function of DataStoreService
.
You can then save keys and values to your DataStore using the SetAsync
function, and retrieve them using the GetAsync
function.
You will have to retrieve saved values using a PlayerAdded
event, and save the desired stat's Value using a PlayerRemoving
event.
--Creating the DataStore local ds = game:GetService("DataStoreService"):GetDataStore("statz"); --Loading stats game.Players.PlayerAdded:Connect(function(plr) local data = ds:GetAsync(plr.UserId); if data then plr:WaitForChild("Kills").Value = data.kills; plr:WaitForChild("Deaths").Value = data.deaths; end end) --Saving stats game.Players.PlayerRemoving:Connect(function(plr) local data = {kills=plr.Kills.Value,deaths=plr.Deaths.Value}; ds:SetAsync(plr.UserId,data); end)