The when i print the loop, it is only finding the first one of each family. Anyone have any thoughts? Thanks :)
when the value is printed, the numbers all come up as nil :(, and i don't know why, so i'm guessing that the values just aren't being saved properly.
local DSService = game:GetService('DataStoreService'):GetDataStore('MagicalnessTesting3') --Change this name to a random name or it will not work
local number = 1
game.Players.PlayerAdded:connect(function(plr)
-- Define variables
local uniquekey = 'id-'..plr.userId
local MagicValues = game.ServerStorage:FindFirstChild("MagicValues"):Clone()
MagicValues.Parent = plr
print("Put MagicValues in player", plr.MagicValues)
wait(2)
local MagicVals = MagicValues:GetDescendants()
local Variables = {}
-- GetAsync
local GetSaved = DSService:GetAsync(uniquekey)
for _,v in pairs(MagicVals) do
if v:IsA'StringValue' or v:IsA'NumberValue' or v:IsA'BoolValue' then
if GetSaved then
v = GetSaved[number]
print(GetSaved[number])
number = number + 1
else
local Valuestosave = {}
table.insert(Valuestosave, v.Name)
Valuestosave[v.Name] = tostring(v.Value)
DSService:SetAsync(uniquekey, Valuestosave)
end
end
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local MagicValues = plr.MagicValues:GetDescendants()
local Valuestosave = {}
DSService:SetAsync(uniquekey, Valuestosave)
for _,v in pairs(MagicValues) do
if v:IsA'StringValue' or v:IsA'NumberValue' or v:IsA'BoolValue' then
table.insert(Valuestosave, v.Name)
Valuestosave[v.Name] = tostring(v.Value)
print(Valuestosave)
end
end
end)

3 comments
well first thing that comes to mind is that the datastor hasnt loaded?
nice job, u got this from alvinbloxx
But seriously instead of doing
if v:IsA'StringValue' or v:IsA'NumberValue' or v:IsA'BoolValue' then ... endjust doif v:IsA'ValueBase' then ... end