Trying to clone names of instances in a table, but output is displaying attempt to index nil with 'Clone'
Server script:
if DroidModel ~= nil then
table.insert(data, {
DroidModel.Name,
DroidModel.Body.Primary.Head.Color.R;
DroidModel.Body.Primary.Head.Color.G;
DroidModel.Body.Primary.Head.Color.B;
DroidModel.Body.Secondary.Head.Color.R;
DroidModel.Body.Secondary.Head.Color.G;
DroidModel.Body.Secondary.Head.Color.B;
DroidModel.Body.Tertiary.Torso.Color.R;
DroidModel.Body.Tertiary.Torso.Color.G;
DroidModel.Body.Tertiary.Torso.Color.B
})
end
Output:
1 Like
Can you share the line that gives the error
1 Like
This is not the line that is erroring.
1 Like
I think its because your adding table to another table, basically,
{{}}
so you will have to access that table in the middle because that’s where the data is stored.
1 Like
Yes, sorry
if success and data then
Player.Droids.Owned.Value = data[1]
if Player.Droids.Owned.Value == true then
print(data[2])
local NewDroid = ReplicatedStorage.Droids:FindFirstChild(tostring(data[1])):Clone()
for i,primary in (NewDroid.Body.Primary:GetChildren()) do
primary.Color = Color3.fromRGB(data[3] * 255, data[4] * 255, data[5] * 255)
end
for i,secondary in (NewDroid.Body.Secondary:GetChildren()) do
secondary.Color = Color3.fromRGB(data[6] * 255, data[7] * 255, data[8] * 255)
end
for i,tertiary in (NewDroid.Body.Tertiary:GetChildren()) do
tertiary.Color = Color3.fromRGB(data[9] * 255, data[10] * 255, data[11] * 255)
end
NewDroid.Parent = Character
NewDroid.HumanoidRootPart.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(-5, 0, 0)
end
print("Data loaded: " .. Player.Name)
Makes sense, how would I go about doing that?
Yes sorry, I’ve included it in another reply.
You can make a loop that adds the contents to the data.
local tabl = {}
local thingstoadd = {
"Poopy",
"Stinky",
1,
2,
3,
}
for i,v in pairs(thingstoadd) do
table.insert(tabl,v)
end
print(#tabl)
sonic_848
(killer)
September 27, 2024, 8:16pm
9
That’s just Re-assignment though. Might as well do table.clone
I don’t know how else he could access the middle table I linked in the other reply.
OP can also try to make a variable of the table inside and just access that table.
table.insert(data, {
DroidModel.Name,
DroidModel.Body.Primary.Head.Color.R;
DroidModel.Body.Primary.Head.Color.G;
DroidModel.Body.Primary.Head.Color.B;
DroidModel.Body.Secondary.Head.Color.R;
DroidModel.Body.Secondary.Head.Color.G;
DroidModel.Body.Secondary.Head.Color.B;
DroidModel.Body.Tertiary.Torso.Color.R;
DroidModel.Body.Tertiary.Torso.Color.G;
DroidModel.Body.Tertiary.Torso.Color.B
})
he’s making a new table and putting all the data in there. so we need to take it out.
sonic_848
(killer)
September 27, 2024, 8:20pm
11
Uhhh maybe just data[1][1]
This is what it prints as
sonic_848
(killer)
September 27, 2024, 8:27pm
15
rustic:
tostring(data[1])
Replace this with data[1][1]
Outputs attempt to index boolean with number
It’s weird as it prints correctly but cloning is the issue
sonic_848
(killer)
September 27, 2024, 8:48pm
18
why don’t u save it to a variable maybe then use the variable?
local DroidName = data[2][1]
Any ideas why the colour’s aren’t saving properly?
Always loading in as black
if DroidModel ~= nil then
table.insert(data, {
DroidModel.Name,
DroidModel.Body.Primary.Head.Color.R;
DroidModel.Body.Primary.Head.Color.G;
DroidModel.Body.Primary.Head.Color.B;
DroidModel.Body.Secondary.Head.Color.R;
DroidModel.Body.Secondary.Head.Color.G;
DroidModel.Body.Secondary.Head.Color.B;
DroidModel.Body.Tertiary.Torso.Color.R;
DroidModel.Body.Tertiary.Torso.Color.G;
DroidModel.Body.Tertiary.Torso.Color.B
})
end
sonic_848
(killer)
September 27, 2024, 10:03pm
21
Can you print and show the data table before you save it and when u get the data?