so I make specific value on leader stats such as kills/death/total kills I only want to save my total kills but it won't save. ``
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("KillsStats")
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder", Player)
Leaderstats.Name = "leaderstats"
local Kill= Instance.new("IntValue", Leaderstats)
Kill.Name = "Kills"
Kill.Value = 0
local deaths = Instance.new("IntValue", Leaderstats)
deaths.Name = "Deaths"
deaths.Value = 0
local Kills= Instance.new("IntValue", Leaderstats)
Kills.Name = "Total Kills"
Kills.Value = 0
Player.CharacterAdded:connect(function(char)
local humanoid
repeat
humanoid = char:FindFirstChild("Humanoid")
wait()
until humanoid
humanoid.Died:connect(function()
deaths.Value = deaths.Value + 1
local Data = DataStore:SetAsync(Player.UserId)
if Data then
Kills.Value = Data
end
end)
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId, {
["Total Kills"] = Player.leaderstats.Kills.Value;})
end)

1 comment
THANK YOU!