Self explinatory, scritp that should do datastores, datastores not loading ):
local KillsDatastore = game:GetService("DataStoreService"):GetDataStore("KillsDatastore")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "Leaderstats"
local Kills = Instance.new("NumberValue", leaderstats)
Kills.Name = "Kills"
Kills.Value = 0
local TotalKills = Instance.new("NumberValue", leaderstats)
TotalKills.Name= "Total Kills"
TotalKills.Value = 0
local CurrentCharacter = Instance.new("StringValue", plr)
CurrentCharacter.Name = "CurrentCharacter"
CurrentCharacter.Value = "Character1"
local success, errormessage = pcall(function()
local Key = plr.UserId
local Data = KillsDatastore:GetAsync(Key)
if Data then
TotalKills.Value = Data[1]
end
end)
while not success do
task.wait(3)
local Key = plr.UserId
local Data = KillsDatastore:GetAsync(Key)
if Data then
TotalKills.Value = Data[1]
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
local Key = plr.UserId
local DataTable = {}
table.insert(DataTable, plr.leaderstats["Total Kills"].Value)
KillsDatastore:SetAsync(Key, DataTable)
end)
while not success do
task.wait(3)
local Key = plr.UserId
local DataTable = {}
table.insert(DataTable, plr.leaderstats["Total Kills"].Value)
KillsDatastore:SetAsync(Key, DataTable)
end
end)