I want to save everything on table please help me this is not working!
local DataStoreService = game:GetService("DataStoreService")
local DataDS = DataStoreService:GetDataStore("OPMLData")
function getData(player)
local success, dataFromDS = pcall(function()
return DataDS:GetAsync(player.UserId)
end)
if dataFromDS then
return dataFromDS
else
return 0
end
if not success then
warn("couldn't get the data properly")
end
end
function saveData(player, valueToSave)
local success, err = pcall(function()
DataDS:SetAsync(player.UserId, valueToSave)
end)
if(not success)then
warn("failed to save data")
end
end
game.Players.PlayerAdded:Connect(function(player)
local playerData = getData(player)
local keeper = Instance.new("Folder",game.ReplicatedStorage)
keeper.Name = player.Name.."Data"
local xp = Instance.new("NumberValue",keeper)
xp.Name = "XP"
xp.Value = 0
local xpneeded = Instance.new("NumberValue",keeper)
xpneeded.Name = "XPtonextlevel"
xpneeded.Value = 200
local lvl = Instance.new("NumberValue",keeper)
lvl.Name = "Level"
lvl.Value = 1
local beli = Instance.new("NumberValue",keeper)
beli.Name = "Beli"
local bounty = Instance.new("NumberValue",keeper)
bounty.Name = "Bounty"
end)
game.Players.PlayerRemoving:Connect(function(plr)
print(plr.Name.." is leaving".. ", trying to save player's data!")
local location = game.ReplicatedStorage[plr.Name.."Data"]
local DataToSave = { location.Level.Value, location.XPtonextlevel.Value, location.Beli.Value, location.XP.Value, location.Bounty.Value }
for _,v in pairs(DataToSave) do
saveData(plr, DataToSave)
end
wait(0.1)
game.ReplicatedStorage[plr.Name.."Data"]:Destroy()
end)

3 comments
12:25:28.611 - ServerScriptService.AddLvandXP:34: attempt to index local 'playerData' (a number value)
12:25:30.667 - Beli is not a valid member of Folder
12:25:34.820 - Script 'ServerScriptService.AddLvandXP', Line 51