Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Attempt to index nil with name and parent?

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

✓ Accepted answer

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)]

3 comments

0

Now it's an instance!

0

Thanks a lot!

0

No problem!!!

This discussion is preserved as it was. New answers, comments, and votes are closed.