Ad
Log in to vote
1

Attempt to index nil with name and parent?

Asked by
CodeWon 121
28 days ago
Edited 28 days ago

The script I supposed to chose a random map and spawn it in. But I got a few errors.

"Attempt to index nil with 'Name' "

Then I changed it a little and got

Attempt to index nil with 'Parent' "

Script:

local ServerStorage = game:GetService("ServerStorage")
local MapsFolder = ServerStorage:WaitForChild("Maps")

while true do

    status.Value = "Intermission"
    wait(10)

    local Maps = MapsFolder:GetChildren()

    local randomMap = math.random(1,#Maps)

    Status.Value = "Map chosen: "..randomMap.Name

    randomMap.Parent = game.Workspace
end

1 answer

Log in to vote
1
Answered by
Xapelize 1459 Moderation Voter
28 days ago
Edited 28 days ago

It is because randomMap value is a random number between 1 to how much children inside maps, BUT number does not have a name, or a parent. It's a string, not an instance. So what are you gonna do is replace line 11 to:

local randomMap = Maps[math.Random(1,#Maps)]
0
Now it's an instance! Xapelize 1459 — 28d
0
Thanks a lot! CodeWon 121 — 28d
0
No problem!!! Xapelize 1459 — 28d
Ad

Answer this question