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

Why do all the parts get removed in my script when I want specific ones to stay?

Asked by 4 years ago

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
0
I'll check it out Nootian 184 — 4y

1 answer

Log in to vote
0
Answered by
Nootian 184
4 years ago
Edited 4 years ago

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
Ad

Answer this question