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

Why does this error appear?

Asked by 8 years ago

So I am making a minigame place. The problem is, team minigames don't work for me.

The mainscript causes errors I can't solve! Can you help?

local feed = game.Workspace.GuiText
function minigame()
local maps = game.Lighting.Minigames:GetChildren()
  local num = math.random(1, #maps)
  local gameChosen = maps[num]:clone()
  local spawns = gameChosen.Spawns:GetChildren()
  local teamGame = gameChosen.Teams
  local raceGame = gameChosen.Race
  local gameAn = game.Workspace.GameIsStarting
  for int = 30, 1, -1 do
    feed.Value = "Intermission: "..int
    wait(1)
  end
  gameAn.Value = true
  local mapName = game.Workspace.MapName
  mapName.Value = gameChosen.Name
  for ready = 10, 1, -1 do
    feed.Value = "Get Ready! "..ready
    wait(1)
  end
  gameAn.Value = false
  for rsg = 3, 1, -1 do
    feed.Value = rsg
    wait(1)
  end
  feed.Value = "Let's go!"
  gameChosen.Parent = workspace
for _, player in pairs(game.Players:GetPlayers()) do
    local character = player.Character
    local targets = player.Targets
    targets.Value = 0
    local randomSpawn = spawns[math.random(#spawns)] -- EDIT
    if character then
        character:MoveTo(randomSpawn.Position) -- EDIT
     end
  end
  wait(0.1)
  feed.Value = ""
  wait(60)
  feed.Value = "Good job guys! Game over!"
  for _, player in pairs(game.Players:GetPlayers()) do
    if teamGame.Value == true then
      local winningTeam = gameChosen:FindFirstChild('WinningTeam')
      local teamName = player.TeamName
      if teamName.Value == winningTeam.Value then
       local points = player.Points
       local xp = player.XP
       points.Value = points.Value + 10
       xp.Value = xp.Value + 20
       else
       local xp = player.XP
       xp.Value = xp.Value + 10
      end
    else
    local ingame = player.InGame
    if ingame == true then
       local points = player.Points
       local xp = player.XP
       points.Value = points.Value + 10
       xp.Value = xp.Value + 20
    end
  end
  wait(3)
  mapName.Value = ""
  gameChosen:remove()
end
end
while true do
    if game.Players.NumPlayers >= 2 then
    minigame()
    else
    wait(0.1)
    feed.Value = "Needs 1 more player!"
    end
  wait()
end

In my output, I get:

07:34:03.949 - Workspace.Script:46: attempt to index local 'winningTeam' (a nil value)

Why is this?

1 answer

Log in to vote
0
Answered by 8 years ago

On line 40 you remove the game, then a few lines later (line 46) you check the removed game for a value... That would be where you've gone wrong.

The following script SHOULD work...

local feed = game.Workspace.GuiText
function minigame()
local maps = game.Lighting.Minigames:GetChildren()
  local num = math.random(1, #maps)
  local gameChosen = maps[num]:clone()
  local spawns = gameChosen.Spawns:GetChildren()
  local teamGame = gameChosen.Teams
  local raceGame = gameChosen.Race
  local gameAn = game.Workspace.GameIsStarting
  for int = 30, 1, -1 do
    feed.Value = "Intermission: "..int
    wait(1)
  end
  gameAn.Value = true
  local mapName = game.Workspace.MapName
  mapName.Value = gameChosen.Name
  for ready = 10, 1, -1 do
    feed.Value = "Get Ready! "..ready
    wait(1)
  end
  gameAn.Value = false
  for rsg = 3, 1, -1 do
    feed.Value = rsg
    wait(1)
  end
  feed.Value = "Let's go!"
  gameChosen.Parent = workspace
for _, player in pairs(game.Players:GetPlayers()) do
    local character = player.Character
    local targets = player.Targets
    targets.Value = 0
    local randomSpawn = spawns[math.random(#spawns)] -- EDIT
    if character then
        character:MoveTo(randomSpawn.Position) -- EDIT
     end
  end
  wait(0.1)
  feed.Value = ""
  wait(60)
  feed.Value = "Good job guys! Game over!"
  for _, player in pairs(game.Players:GetPlayers()) do
    if teamGame.Value == true then
      local winningTeam = gameChosen:FindFirstChild('WinningTeam')
      local teamName = player.TeamName
      if teamName.Value == winningTeam.Value then
       local points = player.Points
       local xp = player.XP
       points.Value = points.Value + 10
       xp.Value = xp.Value + 20
       else
       local xp = player.XP
       xp.Value = xp.Value + 10
      end
    else
    local ingame = player.InGame
    if ingame == true then
       local points = player.Points
       local xp = player.XP
       points.Value = points.Value + 10
       xp.Value = xp.Value + 20
    end
  end
  gameChosen:remove()
  wait(3)
  mapName.Value = ""
end
end
while true do
    if game.Players.NumPlayers >= 2 then
    minigame()
    else
    wait(0.1)
    feed.Value = "Needs 1 more player!"
    end
  wait()
end
0
YOU'RE THE BEST! THANK YOU! NeonicPlasma 181 — 8y
0
No problem darkelementallord 686 — 8y
0
Still didin't work d: NeonicPlasma 181 — 8y
Ad

Answer this question