I'm trying to save an array in the datastore but when I try to set a variable as the saved array, the values return as nil. Can someone tell me what I'm doing wrong?
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("okdata")
game.Players.PlayerAdded:connect(function(plr)
local key = "id-"..plr.UserId
local saves = ds:GetAsync(key)
local points = Instance.new("NumberValue", plr)
points.Name = "Points"
points.Value = 0
local class = Instance.new("StringValue", plr)
class.Name = "Class"
class.Value = "Fighter"
local color = Instance.new("StringValue", plr)
color.Name = "Color"
color.Value = "Bright green"
points.Value = saves[1]
class.Value = saves[2]
color.Value = saves[3]
end)
game.Players.PlayerRemoving:connect(function(plr)
local key = "id-"..plr.UserId
local savearray = {plr.Points.Value, plr.Class.Value, plr.Color.Value}
ds:SetAsync(key,savearray)
end)

1 comment
I see nothing wrong with this script... Weird..