luau is being stubborn. I’m trying to make a clone of the world and stuff it in a worldmodel (like 3 parts, no point in optimization atp)
I specifically coded it so ONLY if it is a basepart or model, it will be cloned. Luau decided not to. It tried cloning Terrain, which they just don’t let you. It stops my entire script.
“…what?”
“HOW???”, I thought to myself…
“i literally EXCLUDED the terrain class… maybe i’ll just have to use a different method… maybe using part:IsA("Terrain") == false…?”
I remember this happening to me with models and primary parts. I would specifically exclude the Primary part of the model yet it always included it, so I resorted to excluding the part called “Primary”. Just wanted to share this error that is very similar to this one.
Terrain is technically considered a BasePart, it’s not just Terrain itself. If you didn’t know, some instances have some kind of subclasses, like how PointLight, SpotLight, and SurfaceLight returns true if you run :IsA("Light"), or how Tool and Actor returns true if you run :IsA("Model").
Now that you know about the subclasses, lets get to the main problem. The problem is how the condition is ordered.
Because Terrain is a BasePart, part:IsA("BasePart") would return true, and in the script you’re checking if parts considered a Model doesn’t have the ClassName equal to Terrain, which will always return true because no instance considered a Model would be Terrain.
So the solution would be to close part:IsA("BasePart") and part:IsA("Model") in a parenthesis.
There you have it, a solution + new information. Happy scripting!
for _, obj in workspace:GetChildren() do
if obj:IsA("Terrain") then
continue
end
if not (obj:IsA("BasePart") or obj:IsA("Model")) then
continue
end
local clone = obj:Clone()
end
This code is not working because the and takes precedence. It’s actually calculating part:IsA("Model") and part.ClassName ~= "Terrain" together. Then it does the or with part:IsA("BasePart"). Since Terrain is a BasePart, it will be true for Terrain. You can fix this by using parenthesis or guard clauses to properly separate the conditions.
if part:IsA("Terrain") then continue end
if part:IsA("BasePart") or part:IsA("Model") then
local clone = part:Clone()
if not clone then continue end
clone.Parent = p1.SurfaceGui.ViewportFrame.WorldModel
end
Keep in mind that if the part has Archivable set to false, it will not be cloned and :Clone() will return nil.
Terrain’s name is Terrain. Terrain is actually one “part”. You just need to not pick that one single special object that is named Terrain..
local set = game:GetService("ReplicatedStorage"):WaitForChild("Set") --wherever
for _, obj in workspace:GetChildren() do
if obj.Name ~= "Terrain" and not obj:FindFirstChild("Humanoid") then
local clone = obj:Clone() clone.Parent = set
end
end