Cannot change Parent of type Terrain

For i,v loop not working properly

I’m trying to get everything in the workspace and put it into a viewport frame but it keeps trying to put the terrain in even though I’ve put an if statement to make sure that it does not take those items.

local ToolBar = plugin:CreateToolbar("Alpha")
local PluginButton = ToolBar:CreateButton("", "Alpha", "")

local New_Gui ="ScreenGui")
New_Gui.Enabled = false
New_Gui.Name = "Gui"
New_Gui.Parent = game.CoreGui

local Viewport_Frame ="ViewportFrame")
Viewport_Frame.BackgroundColor3 = Color3.fromRGB(95, 95, 95)
Viewport_Frame.CurrentCamera = workspace.Camera
Viewport_Frame.Size = UDim2.fromScale(1,1)
Viewport_Frame.Parent = New_Gui

for i,v in pairs(workspace:GetChildren()) do 
	if v.ClassName ~= "Terrain" or "Camera" then
	v.Parent = Viewport_Frame

	New_Gui.Enabled = not New_Gui.Enabled

This behavior occurs because your if statement always evaluates to true. Currently, the if statement checks if v.ClassName is not equal to “Terrain” OR if “Camera” is a truthy value, where the latter always results in true. To rectify this, you should modify the if statement as follows:

if v.ClassName ~= "Terrain" and v.ClassName ~= "Camera" then

This version ensures that v.ClassName is not equal to either of those strings before proceeding to the code inside the block.

thank you for being so helpful, i’m pretty sure thats one of the first things they talk about in the programing in lua book

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.