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

Is there an easier way of doing this? (lol)

Asked by 9 years ago

A more efficient script?

local burn = script.Burn
local celebration = script.Celebration
local deep = script["Deep Piano Electronic"]
local dj = script["Dj Got Us Falling In Love Again"]
local dub = script.Dubstep
local fun = script["Fun Electric"]
local glad = script["Glad You Came"]
local blue = script["I'm Blue"]
local mirrior = script.Mirrors
local wut = script.Music
local light = script["So light em up"]
local taco = script.Tacos
local love = script["This Is Love"]
local yeah = script["Usher - Yeah"]
local with = script["Without You"]

wait(1)
    local player = game.Players.LocalPlayer
        local m = math.random(1,15)
        if m==1 
            and player.TeamColor == BrickColor.new("Medium stone grey") then
                burn.Volume = 1
                    burn:Play()

        else
            if m==2 
                and player.TeamColor == BrickColor.new("Medium stone grey") then
                    celebration.Volume = 1
                        celebration:Play()


            else
                if m==3 
                    and player.TeamColor == BrickColor.new("Medium stone grey") then
                        deep.Volume = 1
                            deep:Play()


                else
                    if m==4 
                        and player.TeamColor == BrickColor.new("Medium stone grey") then
                            dj.Volume = 1
                                dj:Play()


                    else
                        if m==5 
                            and player.TeamColor == BrickColor.new("Medium stone grey") then
                                dub.Volume = 1
                                    dub:Play()


                        else
                            if m==6 
                                and player.TeamColor == BrickColor.new("Medium stone grey") then
                                    fun.Volume = 1
                                        fun:Play()


                            else
                                if m==7 
                                    and player.TeamColor == BrickColor.new("Medium stone grey") then
                                        glad.Volume = 1
                                            glad:Play()


                                else
                                    if m==8 
                                        and player.TeamColor == BrickColor.new("Medium stone grey") then
                                            blue.Volume = 1
                                                blue:Play()


                                    else
                                        if m==9 
                                            and player.TeamColor == BrickColor.new("Medium stone grey") then
                                                mirrior.Volume = 1
                                                    mirrior:Play()


                                        else
                                            if m==10 
                                                and player.TeamColor == BrickColor.new("Medium stone grey") then
                                                    wut.Volume = 1
                                                        wut:Play()


                                            else
                                                if m==11 
                                                    and player.TeamColor == BrickColor.new("Medium stone grey") then
                                                        light.Volume = 1
                                                            light:Play()


                                                else
                                                    if m==12 
                                                        and player.TeamColor == BrickColor.new("Medium stone grey") then
                                                            taco.Volume = 1
                                                                taco:Play()


                                                    else
                                                        if m==13 
                                                            and player.TeamColor == BrickColor.new("Medium stone grey") then
                                                                love.Volume = 1
                                                                    love:Play()


                                                        else
                                                            if m==14 
                                                                and player.TeamColor == BrickColor.new("Medium stone grey") then
                                                                    yeah.Volume = 1
                                                                        yeah:Play()


                                                            else
                                                                if m==15 
                                                                    and player.TeamColor == BrickColor.new("Medium stone grey") then
                                                                        with.Volume = 1
                                                                            with:Play()


        else
            burn.Volume = 0
                celebration.Volume = 0
                    deep.Volume = 0
                        dj.Volume = 0
                            dub.Volume = 0
                                fun.Volume = 0
                                    glad.Volume = 0
                                        blue.Volume = 0
                                            mirrior.Volume = 0
                                                wut.Volume = 0
                                                    light.Volume = 0
                                                        taco.Volume = 0
                                                            love.Volume = 0
                                                                yeah.Volume = 0
                                                                    with.Volume = 0
                                                                end
                                                            end
                                                        end
                                                    end
                                                end
                                            end
                                        end
                                    end
                                end
                            end
                        end
                    end
                end
            end
        end

1 answer

Log in to vote
0
Answered by 9 years ago

Yes.

First, a tip: you can use "elseif" instead of "else [newline] if", thereby saving an indent.

To make your script more efficient, we can use a table, like this:

local songs = script:GetChildren()
wait(1)
local player = game.Players.LocalPlayer
if player.TeamColor == BrickColor.new("Medium stone grey") then
    local index = math.random(1, #songs)
    songs[index].Volume = 1
    songs[index]:Play()
end

Note: If the script has children that are not songs, assign to 'songs' this way instead:

songs = {
    script.Burn,
    --etc
}

For more information on tables, see http://wiki.roblox.com/index.php?title=Table.

0
okay thank you, ill check it out and see how it works CarterTheHippo 120 — 9y
0
works great thanks! :D CarterTheHippo 120 — 9y
Ad

Answer this question