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

Why won't this work?

Asked by 8 years ago

Here is the script that my friend gave me with a few edits:

minigames = game.Lighting.Minigames:GetChildren()
map = math.random(1, #minigames)

function Intermission()
    wait(2)
    for value = 35, 0, -1 do
        wait(1)
        game.Workspace.Timer.Value = "The game will start in "..value.." seconds."
    end
    wait(1)
    game.Workspace.Timer.Value = "Which map will we choose?"
    wait(3)
    game.Workspace.Timer.Value = "Map: "..map.Name
    return true
end

while true do
    wait(1)
    local Int = Intermission()
end

The problem is that line 13 does not work. Why?

1 answer

Log in to vote
2
Answered by 8 years ago

The problem.

No introductions, let's cut to the chase. map is a number. A random number between 1, and the number of minigames. not an instance. Lots of people make that mistake. If you were to return the map, it would return the random number between 1 and the # of maps. Why? because that's how math.random works. Only on numbers. Recieve 2 numbers, return one number. Not an instance, a number.

The Solution.

Now that we have the problem. let's find the solution. In tables (GetChildren returns a table) We can use table[number] to find that index (or number) in a table. So how would we apply this to this script? Glad you asked.

minigames = game.Lighting.Minigames:GetChildren() -- get the table of minigames
number = math.random(1,#minigames) -- define a number that's randomly chosen between 1 and the number of minigames
map = minigames[number] -- Iterate through the table of minigames to locate the number.

The Finished Script

minigames = game.Lighting.Minigames:GetChildren()
number = math.random(1, #minigames)
map = minigames[number]

function Intermission()
    wait(2)
    for value = 35, 0, -1 do
        wait(1)
        game.Workspace.Timer.Value = "The game will start in "..value.." seconds."
    end
    wait(1)
    game.Workspace.Timer.Value = "Which map will we choose?"
    wait(3)
    game.Workspace.Timer.Value = "Map: "..map.Name
    return true
end

while true do
    wait(1)
    local Int = Intermission()
end


0
Good answer! You completely solved my problem! NeonicPlasma 181 — 8y
Ad

Answer this question