Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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:

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

1 comment

0

I'll check it out

1 answer

✓ Accepted answer

Solution The script is all good!, only one mistake, and a suggestion. See line 30, Transparency spelled wrong


See line 10, doing #Table gets the size of the table, is more efficient

Your problem may be you aren't naming the parts correctly

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

This discussion is preserved as it was. New answers, comments, and votes are closed.