The question title is what the output id reading. "Cannot store Array in DataStore". How can I fix this?
It was working so far with Exp, Rank, and RankVal, but now after adding RunVal, WalkVal, and Cash it does not work.
Here's my code so far:
local dss = game:GetService("DataStoreService"):GetDataStore("Data") -- Give it a name.
game.Players.PlayerAdded:connect(function(plr)
local UniqueKey = 'id-'..plr.UserId
local stats = Instance.new("Folder", plr)
stats.Name = "leaderstats"
local rank = Instance.new("StringValue", stats)
rank.Name = "Rank"
rank.Value = "Newbie"
local val = Instance.new("IntValue", stats)
val.Name = "RankVal"
val.Value = 1
local exp1 = Instance.new("IntValue", stats)
exp1.Name = "Exp"
exp1.Value = 0
local run = Instance.new("IntValue", plr)
run.Name = "RunVal"
run.Value = 50
local walk = Instance.new("IntValue", plr)
walk.Name = "WalkVal"
walk.Value = 35
local cash = Instance.new("IntValue", stats)
cash.Name = "Cash"
cash.Value = 0
local GetSaved = dss:GetAsync(UniqueKey)
if GetSaved then
rank.Value = GetSaved[1]
val.Value = GetSaved[2]
exp1.Value = GetSaved[3]
run.Value = GetSaved[4]
walk.Value = GetSaved[5]
cash.Value = GetSaved[6]
else
local toSave = {rank.Value, val.Value, exp1.Value, run.Value, walk.Value, cash.Value}
dss:SetAsync(UniqueKey, toSave)
end
game.ReplicatedStorage.Event:FireAllClients(plr.Name, val.Value);
val.Changed:connect(function()
game.ReplicatedStorage.Event:FireAllClients(plr.Name, val.Value);
end)
end)
game.Players.PlayerRemoving:connect(function(plr)
local UniqueKey = 'id-'..plr.UserId
local d = plr.leaderstats
local savetable = {d.Rank.Value, d.RankVal.Value, d.Exp.Value, plr.RunVal, plr.WalkVal, d.Cash} -- A table to hold/save all the values.
dss:SetAsync(UniqueKey,savetable)
end)
