So I was doing some commissioned work for a friend of mine, and I was doing some table datastores for the kill/death ratio thing
local datastore = game:GetService("DataStoreService"):GetDataStore("SBdata")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = plr
leaderstats.Name = "leaderstats"
local kills = Instance.new("IntValue")
kills.Parent = leaderstats
kills.Name = "Kills"
local deaths = Instance.new("IntValue")
deaths.Parent = leaderstats
deaths.Name = "Deaths"
local dataTable = {}
dataTable.kills = kills.Value
dataTable.deaths = deaths.Value
local success,failure = pcall(function()
datastore:SetAsync(plr.UserId,dataTable)
end)
if success then
print("Data saved")
else
warn("data failed to save")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local dataTable
local success,failure = pcall(function()
dataTable = datastore:GetAsync(plr.UserId)
end)
if success and dataTable then
plr.leaderstats.Kills.Value = dataTable.kills
plr.leaderstats.Deaths.Value = dataTable.deaths
print("successfully loaded")
elseif failure then
warn("data failed to load")
end
end)
I don't understand why this isn't working...
Am I doing something wrong?
