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
m = Instance.new("Message")
h = Instance.new("Hint")
m.Parent = game.Workspace
h.Parent = game.Workspace
while true do
    if game.Players.NumPlayers == 1 then
        m.Text = "Loading-Please wait."
        wait(3)
        Spawns = game.Workspace.Elevator.ElevatorSpawn:GetChildren()
        Spawnz = game.Workspace.LobbySpawn:GetChildren()
        m.Text = "Teleporting to Elevator"
        wait(1)
        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[1].Position)
                end
            end
        end
    end
    wait(3)
end

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