Why do all the parts get removed in my script when I want specific ones to stay?
Hi! I'm pretty new to scripting and I'm wondering what's wrong with my script and why it removes all the parts instead of all the parts apart from the colour selected. (hope that makes sense)
Here's my script:
01 | while #game.Players:GetPlayers() < 1 do |
06 | while #game.Players:GetPlayers() < 1 do |
09 | local colours = { "Red" , "Orange" , "Yellow" , "Green" , "Dark Blue" , "Light Blue" , "Pink" , "Purple" } |
10 | local randomColour = math.random( 1 , 8 ) |
11 | local Parts = game.Workspace.GameParts:GetChildren() |
17 | print ( "Selecting safe part..." ) |
21 | local chosenColour = (colours [ randomColour ] ) |
22 | print (colours [ randomColour ] ) |
24 | for _, v in pairs (Parts) do |
25 | if v:IsA( "Part" ) and v.Name = = chosenColour then |
26 | v.Parent = game.Workspace.GameParts.safeParts |
28 | elseif v:IsA( "Part" ) then |
29 | print ( "Removing parts." ) |
37 | print ( "Parts removed." ) |
42 | for i,v in pairs (workspace.GameParts.unsafeParts:GetChildren()) do |
47 | colours [ randomColour ] .Parent = game.Workspace.GameParts.unsafeParts |
51 | print ( "Game Over! A new round will be starting soon." ) |