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

Attempt to index nil with 'GetChildren'?

Asked by 4 years ago
    local nowMap = workspace.Maps:GetChildren()

    local players = game.Players:GetChildren()
    for i = 1,#players do

        if players[i].Character ~= nil then
            local nowMap = nowMap.MapTeleports:GetChildren()
            local spawnLocation = math.random(1,#nowMap.MapTeleports:GetChildren())
            players[i].Character:MoveTo(spawnLocation.Position)
            players[i].Character.Parent = workspace.Ingame
        end
    end
0
Wait Which Line Is The Error in? There Are More GetChildren()'s then 1 crueluu 169 — 4y
0
line 07 Ban_LOLOLOAWoLO 0 — 4y
0
You made a very simple mistake its because MapTeleport hasn't been defined. What I mean by that is your storing a function :GetChildren to your script which will cause an error JesseSong 3916 — 4y
0
And its best to use a generic for loops as this will repeat the action for a period of time. And loop through the objects. JesseSong 3916 — 4y

4 answers

Log in to vote
1
Answered by
Audiimo 105
4 years ago
Edited 4 years ago

You're problem is coming from this line: local nowMap = workspace.Maps:GetChildren()

In line 7, you attempt to use this variable nowMap to access the spawning ports but instead you are trying to access a Table which causes you to error. :GetChildren()creates a table of all the children of that part, but doesn't apply to specific part. See what I mean?

You'll need to change or add a variable that references the specifc map, or the spawn ports, so you can appropriately acess them. So by, let's say, changing your nowMap variable by removing the :GetChildren() could solve your issue or creating a new variable that is assigned to the spawn ports (without the :GetChildren() part). Hope this Helps! :)

-Audiimo

Ad
Log in to vote
0
Answered by 4 years ago

Im having this problem with :WaitForChild.

Log in to vote
0
Answered by
IcyMizu 122
4 years ago
Edited 4 years ago
local nowMap = workspace.Maps:GetChildren()

local players = game.Players:GetChildren()
for i = 1,#players do

    if players[i].Character ~= nil then
        local nowMap = nowMap.MapTeleports:GetChildren()
        local spawnLocation = math.random(1,#nowMap.MapTeleports:GetChildren())
        players[i].Character:MoveTo(spawnLocation.Position)
        players[i].Character.Parent = workspace.Ingame
    end
end

im not sure what u are trying to do here u get the children of nowmap in the firstline and then u try to use nowmap again so ur bassicly doing this

workspace.Maps:GetChildren().MapTeleports:GetChildren()

what are u exactly trying to do here? if u just want to get the children of MapTeleports u could do this

workspace.Maps.MapTeleports:GetChildren()
Log in to vote
0
Answered by
crueluu 169
4 years ago
Edited 4 years ago

Hmm i Noticed That You Refrenced nowMap To Multiple Objects Not Just One


local nowMap = worspace.Maps:GetChildren()

Is That Intended? If It Is Then, You Can Use In Pairs Loop Instead, Reply With More Info About Your code And i'll Hopefully Respond With A Solution. , Theres Another Mistake You Refrenced nowMap Twice Which Changed nowMap's Original Refrence Perhaps Change line (07) local nowMap to another name? Because I Dont Think You Can Refrence One local to More than One Object.

0
This code is wrong. JesseSong 3916 — 4y
0
You misspelled workspace JesseSong 3916 — 4y
0
And I believe you can store multiply variables. JesseSong 3916 — 4y

Answer this question