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
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.