for i,v in pairs(game.Workspace:GetChildren()) do if v:IsA('Tool') then end if v:IsA('Part') then end end for i,v in pairs(game.Workspace:GetChildren()) do if v:IsA('Tool') then elseif v:IsA('Part') then end end
Does anyone know what difference this makes and what I should use?
Here's a comparison
for i,v in pairs(game.Workspace:GetChildren()) do if v:IsA('Tool') then --//v:IsA("Tool") == true; execute code end if v:IsA('Part') then --//v:IsA("Part") == true; execute code end end --//Is not the same as: for i,v in pairs(game.Workspace:GetChildren()) do if v:IsA('Tool') then --//v:IsA("Tool") == true; execute code elseif v:IsA('Part') then --//v:IsA("Tool") == false, and v:IsA("Part") == true; execute code end end
Logic wise these aren't the same thing. A more apt comparison would be
for i,v in pairs(game.Workspace:GetChildren()) do if v:IsA('Tool') then --//v:IsA("Tool") == true; execute code elseif v:IsA('Part') then --//v:IsA("Tool") == false, and v:IsA("Part") == true; execute code end end --//Is the same as: for i,v in pairs(game.Workspace:GetChildren()) do if v:IsA('Tool') then --//v:IsA("Tool") == true; execute code end if not v:IsA('Tool') and v:IsA('Part') then --//v:IsA("Tool") == false, and v:IsA("Part") == true; execute code end end
In this one you could just use an elseif instead of two if statements since they do the same thing logic wise.
Just depends on what you need them for but you can make do without an elseif if you really wanted to, but at the cost of a bit of organization within your code.
Elseif makes your code look nicer and you don’t have to put multiple ends.