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:
while #game.Players:GetPlayers() < 1 do -- S E I for i = 1, 10, 1 do while #game.Players:GetPlayers() < 1 do local colours = {"Red","Orange", "Yellow", "Green", "Dark Blue", "Light Blue", "Pink", "Purple"} local randomColour = math.random(1,8) local Parts = game.Workspace.GameParts:GetChildren() print("Get ready!") wait(5) print ("Selecting safe part...") wait(2) local chosenColour = (colours[randomColour]) print(colours[randomColour]) for _, v in pairs(Parts) do if v:IsA("Part") and v.Name == chosenColour then v.Parent = game.Workspace.GameParts.safeParts print("Part moved") elseif v:IsA("Part") then print("Removing parts.") v.Transparancy = 1 v.CanCollide = false end end wait(5) print("Parts removed.") wait(4) --Making the parts visible + can collide for i,v in pairs(workspace.GameParts.unsafeParts:GetChildren()) do v.Transparency = 0 v.CanCollide = true end colours[randomColour].Parent = game.Workspace.GameParts.unsafeParts end print("Game Over! A new round will be starting soon.") end end
Solution The script is all good!, only one mistake, and a suggestion.
while #game.Players:GetPlayers() < 1 do -- S E I for i = 1, 10, 1 do while #game.Players:GetPlayers() < 1 do local colours = {"Red","Orange", "Yellow", "Green", "Dark Blue", "Light Blue", "Pink", "Purple"} local randomColour = math.random(1,#colours) local Parts = game.Workspace.GameParts:GetChildren() print("Get ready!") wait(5) print ("Selecting safe part...") wait(2) local chosenColour = (colours[randomColour]) print(colours[randomColour]) for _, v in pairs(Parts) do if v:IsA("Part") and v.Name == chosenColour then v.Parent = game.Workspace.GameParts.safeParts print("Part moved") elseif v:IsA("Part") then print("Removing parts.") v.Transparancy = 1 v.CanCollide = false end end wait(5) print("Parts removed.") wait(4) --Making the parts visible + can collide for i,v in pairs(workspace.GameParts.unsafeParts:GetChildren()) do v.Transparency = 0 v.CanCollide = true end colours[randomColour].Parent = game.Workspace.GameParts.unsafeParts end print("Game Over! A new round will be starting soon.") end end