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

How to fix the error: "Attempt to index a nil value"? Help please.

Asked by
Vido01 5
8 years ago
01m = Instance.new("Message")
02h = Instance.new("Hint")
03m.Parent = game.Workspace
04h.Parent = game.Workspace
05while true do
06    if game.Players.NumPlayers == 1 then
07        m.Text = "Loading-Please wait."
08        wait(3)
09        Spawns = game.Workspace.Elevator.ElevatorSpawn:GetChildren()
10        Spawnz = game.Workspace.LobbySpawn:GetChildren()
11        m.Text = "Teleporting to Elevator"
12        wait(1)
13        for i, v in pairs(game.Players:GetPlayers()) do
14            name = v.Name
15            check = game.Workspace:FindFirstChild(name)
View all 25 lines...

Whenever I run this script the output states: attempt to index field '?' (a nil value). The line it is having the error is the line that says: check:MoveTo(Spawns[1].Position). It doesn't seem to be recognizing "Spawns" as a variable. In the variables of Spawns and Spawnz the ElevatorSpawn and LobbySpawn are both models, each containing 10 parts inside of them.

0
Most likely Spawns[1] doesn't exist. Write print(Spawns[1]) on line 29. 1waffle1 2908 — 8y
0
edited to fix formatting BlueTaslem 18071 — 8y
0
1. 'Spawns' isn't define in this code.. 2. Is Spawns a :GetChildren() of a model? It's unclear in the way you said it TheDeadlyPanther 2460 — 8y
0
it looks like "ElevatorSpawn" maybe is empty, are you sure there is something in that model? cheatmaster18 155 — 8y

Answer this question