Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

if statement in a for loop not checking variables in an instance?

Asked by 2 years ago

Im making a game that has autogenerated rooms, and items that get moved to folders in the workspace when the game is loaded, however, I can t seem to get the if statements to work. I've tried many things and have not found a solution.

local function checkMoveDarkZone()
    for _, room in pairs(roomsFolder:GetChildren()) do
        for _, darkZonept in pairs(room:GetChildren()) do
            if darkZonept:IsA("BasePart") then
                if darkZonept.Name == "DarkZonePt" then
                    darkZonept.Parent = zoneFolder:WaitForChild("DarkZone")
                end
            end
        end
    end
end

ive tried using "print" to check where the problem is, though it only works in code leading up to the if statements. also, there are no warnings in the output.

0
Also, you could just do if darkZonept:IsA("BasePart") and darkZonept.Name == "DarkZonePt" later, it makes for better code! robert19735 17 — 2y
0
By the way, is the script local, or server side? robert19735 17 — 2y

Answer this question