I am working on a datastore loading system that will place models into the world wherever the player put them last. However, I am running into an issue, particularly with setting the orientation of a model whose data was saved as 0.
The exact error I am receiving:
ServerScriptService.BuildingDatastore:71: attempt to perform arithmetic (mul) on nil and number
I am assuming this error is because the 6, 7, and 8 values I am pulling from the Datastore are = 0. Here’s the relevant code I am using:
for i, obj in ipairs(data) do
print(obj[1])
local buildingTemplate = game.ReplicatedStorage.PartsAndModels.Models:FindFirstChild(obj[1])
local newBuilding = buildingTemplate:Clone()
newBuilding.Parent = game.Workspace.Buildings
newBuilding.PrimaryPart.CFrame = CFrame.new(obj[3], obj[4], obj[5])
newBuilding.PrimaryPart.CFrame *= CFrame.Angles(obj[6]*math.pi/180, obj[7]*math.pi/180, obj[8]*math.pi/180)
--THE ABOVE LINE IS WHERE THE ERROR IS OCCURRING
if data[9] == true then
for i, part in ipairs(obj:GetChildren()) do
if part:IsA("Part") then
part.CanCollide = false
part.Transparency = 0.5
part.BrickColor = BrickColor.new("Pastel light blue")
end
end
obj:FindFirstChild("PartsListGui").HandlerScript.Enabled = true
else if data[9] == false then
obj:FindFirstChild("PartsListGui"):Destroy()
end
end
end
And, just as proof that those values exist as zero:
Any tips on dealing with this?