I have created a folder and placed the important parts of my game inside of it, and now I want to endlessly delete any objects that are not within the folder
Here is the script:
while true do local workchild = game.Workspace:GetChildren() for i = 1, #workchild do if workchild[i].ClassName ~= "Folder" or "Terrain" then workchild[i]:Destroy() end end wait(0.01) end
The problem here is that the if statement gets ignored and the script is attempts to destroy the terrain - which is something it cannot do.- This causes an error, the script stops, and i'm sure this isn't the only problem with the script.
Hey SparklingFruitPunch,
local x = true; -- Variable declaration for a boolean with the value 'true'. local y = false; -- Variable declaration for a boolean with the value 'false'. if x or y then -- First checks if 'x' is true and if it is then it moves on and doesn't even look at the second part however, if 'x' is false then it will move on to the next part of the if statement to check if 'y' is false or true and if it's true then it will pass the if statement. print("X is true."); end
local str = "Terrain"; -- Variable declaration for the string "Terrain" if str then -- Checks if str is not nil. print("The string is 'Terrain'"); end
local folder, terrain = "Folder", "Terrain"; local parts = workspace:GetChildren(); for i = 1, #parts do if parts[i].ClassName ~= folder and parts[i].ClassName ~= terrain then print("It's not a folder and it's not terrain."); end end
As you can see above I restated to check if the classname is 'Terrain'. You have to make sure that you restate that because computers don't understand if you mean either of the options which is why you must restate the property you are checking.
~~ KingLoneCat