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

Will someone tell me why line 31 keeps erroring out and whats causing it?

Asked by
Prioxis 673 Moderation Voter
10 years ago

I'm making a minigames game but the main script it errors out every time on line 31.... will someone please tell me why? and fix it?

minigames = game.Lighting.minigames:GetChildren()

h = Instance.new("Hint", Workspace)

function removePlate()
    plates = game.Workspace.DissapearingPlates.Plates:GetChildren()
    ranNum1 = math.random(1, #plates)
    ranNum2 = 1
    while ranNum1 == ranNum2 do
        ranNum2 = math.random(1, #plates)
        wait()
    end
    plateChosen = plates(ranNum1)
    plateChosen2 = plates(ranNum2)
    for i = 0, 1, 0.05 do
        plateChosen = plates(ranNum1)
        plateChosen2 = plates(ranNum2)
        for i = 0, 1, 0.05 do
            plateChosen.Transparency = i
            plateChosen2.Transparency = i
            wait()
        end
        plateChosen:Destroy()
        plateChosen2:Destroy()
    end
end

while true do

if game.Players.NumPlayers > 1 then
    h.Text =    "Deciding which game to play."
    wait(1)
    ranGame = math.random(1, #minigames)
    gameChosen = minigames(ranGame)
    h.Text = "Minigame chosen: "..gameChosen.Name
    wait(3)
    gameChosenClone = gameChosen:Clone()
    gameChosenClone.Parent = game.Workspace
    wait(3)
    --teleporting
    spawns = gameChosenClone.Spawns:GetChildren()
    for i, v in pairs (game.Players:GetPlayers()) do
        name = v.Name
        check = game.Workspace:FindFirstChild(name)
        if check then
            checkHumanoid = check:FindFirstChild("Humanoid")
            if checkHumanoid then
               check:MoveTo(spawns[i].Position)
            end
        end
    end
    for i  = 3, 1, -1 do
        h.Text = "Game Begins: ".. i
        wait(1)
    end
    if gameChosenClone.Name == "DissapearingPlates" then
        timeTilGameEnds = 20
    end
    --Countdown until game ends
    for i = timeTilGameEnds, 1, -1 do
        h.Text = "Time Left : ".. i
        removePlate()
        wait(1)
    h.Text = "Game ended!"
    wait(3)
    h.Text = "Giving Points to players who won"
    for i, v in pairs(game.Players:GetPlayers()) do
        ingame = v:FindFirstChild("InGame")
        if ingame then
            v.leaderstats.Points.Value = v.leaderstats.Points.Value +10
        end
    end
    wait(3)
    gameChosenClone:Destroy()
    wait(60)
    end
else
    h.Text = "there needs to be more than 1 player to start"
    wait(1)
    end
end
0
Any output at all? If there is some output, it would be quite helpful if you added it! OniiCh_n 410 — 10y
0
yeah sorry I forgot 13:59:11.510 - Workspace.MainScript:34: attempt to call global 'minigames' (a table value) 13:59:11.511 - Stack Begin 13:59:11.511 - Script 'Workspace.MainScript', Line 34 13:59:11.512 - Stack End? Prioxis 673 — 10y

1 answer

Log in to vote
2
Answered by 10 years ago

On line 34, use [brackets], not (parenthesis). Although I think you also need to use math.floor / math.ceil to make sure the number chosen is not a decimal, although I'm not sure.

local ranGame = math.floor(math.random(1,#minigames)) --I think this is needed, correct me if I am wrong
local gameChosen = minigames[ranGame] --Using brackets
--Also I would put the word local before the variables so I don't end up declaring them globally. This isn't needed though.
0
alright yay thank you Prioxis 673 — 10y
0
math.random only returns whole numbers, not decimals. SlickPwner 534 — 10y
0
Just tested math.random(), and it returns a decimal. Octillerysnacker 115 — 10y
Ad

Answer this question