So i was Trying to Make the Color of the Parts save But then it told me Arrays Can’t be stored so i used a way to save them Then when it is getting the Data it gave me that Error i would be Grateful if anyone can help. Thank you and have a Good day!
Code:
local DataStore = game:GetService("DataStoreService")
local Data = DataStore:GetDataStore("Data471112")
local RS = game:GetService("ReplicatedStorage")
local Builder = RS:WaitForChild("Builder")
local function GetBase(player)
coroutine.resume(coroutine.create(function()
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("Model") and v.Player.Value == "" then
v.Player.Value = player.Name
local Items = Data:GetAsync(player.UserId)
print("Step1")
if Items then
print("Step2")
for i,item in pairs(Items) do
print("found")
local ItemName = item[1]
print(ItemName)
print("found0.5")
local CFm = CFrame.new(unpack(item[2]))
print("found1")
local CloneItem = Builder:FindFirstChild(ItemName):Clone()
print("found2")
CloneItem.Parent = v.ItemHolder
print("found3")
local nCFm = v.Place.CFrame:ToWorldSpace(CFm)
print("found4")
if CloneItem:IsA("Model") then
print("Isa model")
CloneItem:SetPrimaryPartCFrame(nCFm)
else
local color = BrickColor.new(unpack(item[2]))
CloneItem.CFrame = nCFm
end
end
end
return
end
end
end))
end
local function GrabBase(player)
coroutine.resume(coroutine.create(function()
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("Model") and v.Player.Value == player.Name then
v.Player.Value = ""
print("Mwoaw")
local Items = {}
for i,item in pairs(v.ItemHolder:GetChildren()) do
if item:IsA("Model") then
print("Model")
local CFm = v.Place.CFrame:toObjectSpace(item.PrimaryPart.CFrame)
table.insert(Items,{item.Name,{CFm:components()}})
item:Destroy()
else
print("Part")
local Color = item.BrickColor
local CFm = v.Place.CFrame:toObjectSpace(item.CFrame)
table.insert(Items,{item.Name,{CFm:components()},{Color}})
item:Destroy()
end
end
wait()
Data:SetAsync(player.UserId,game:GetService("HttpService"):JSONEncode(Items))
end
end
end))
end
game.Players.PlayerAdded:Connect(function(Player)
GetBase(Player)
end)
game.Players.PlayerRemoving:Connect(function(Player)
GrabBase(Player)
end)
i get an error that says invalid argument #1 to ‘pairs’ (table expected, got string)
with
for i,item in pairs{Items}
no errors but it prints everything as nil
and can you explain in depth what u mean by something that isn’t a table im new to arrays and stuff sorry if i don’t understand some stuff you sat
You defined Items as the datastore:GetAsync bit, but that obviously doesnt return a table as you probably haven’t saved a table to the datastore yet. A table can be anything: like {1; 2; 3} to even Players:GetPlayers()
(GetPlayers returns an array of names)
I also have no idea what you’re trying to achieve with your code, so maybe elaborate a bit?
So what I have is a plot saving script and in the building system I have u can customize that build and change its colours and material the plot saving was working fine until I tried to make it save the colour
This is nothing to do with your error directly but may be related to why your getting some weird data saving / loading.
I believe you cant store color3 values, so its best to store it as an integer attached to a string / binary number defining if its ‘R’, ‘G’, ‘B’ to prevent errors.
Yes like you and @GalaxyGourmet said I used to have it Data:SetAsync(player.UserId , Items) but it told me you cant save arrays so I used this way but I think why this is happening because I was saving the color3 value the wrong way