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

How would i fix my map randomiser with a number error?

I have been trying to make a map randomiser for the past 2 hours and i am having trouble it says "attempt to index number with 'Map'" on line 3 i have tried math.random(1, #Maps), random.new(1, #Maps) and neither have worked please help as i cant continue making a game without this working.

EDIT: I changed the code a little still dosent work NEW ERROR: ServerScriptService.MapChooser.Selector:14: attempt to index number with 'Sky'

local Maps = game.ServerStorage:WaitForChild("Maps"):GetChildren()
local Map = math.random(1, #Maps)
local MapClone = Maps[Map]:Clone()
local Intermission = game.ReplicatedStorage:WaitForChild("MapStuff"):WaitForChild("Intermission")

while wait() do
	print("Intermission.")
	if Intermission.Value == true then
		wait()
	elseif Intermission.Value == false then
		print("No Longer Intermission.")
		MapClone.Map.Parent = workspace
		print("Cloned To Workspace.")
		Map.Sky.Parent = game.Lighting
		print("Lighting.")
	end
end

5 comments

0

Try doing Map[Sky].Parent

0

When you are using :GetChildren() you are creating an array. So now to find a random map in that array, you need to generate a random number key(using math.random()) then you need to reference the array as you usually would. Maps[math.random(1,#Maps)]

1

ForeverBrown i already fixed it thanks to HappyJakeyBoy

1

Just giving a brief description of what is actually happening.

1

Oh thanks

3 answers

✓ Accepted answer

Try this

local Maps = game.ServerStorage:WaitForChild("Maps"):GetChildren()
local Map = math.random(1, #Maps)
local MapClone = Maps[Map]:Clone()
local Intermission = game.ReplicatedStorage:WaitForChild("MapStuff"):WaitForChild("Intermission")

while wait() do
	print("Intermission.")
	if Intermission.Value == true then
		wait()
	elseif Intermission.Value == false then
		print("No Longer Intermission.")
		MapClone.Map.Parent = workspace
		print("Cloned To Workspace.")
		MapClone.Sky.Parent = game.Lighting
		print("Lighting.")
	end
end

7 comments

0

Thanks Also Your Welcome :D

0

Answer unaccepted. Horrible answer, lacks the information necessary to help the asker.

1

Actually BashCaster it worked fine

0

It's a bad answer because it does not explain the code. It is a spoonfeed answer.

1

he explained the code through discord he said he had go shops so he went to explain on discord

1

When i did Map.Sky.Parent it checked the model for Map for sky even though sky is under the folder with same parent as map

0

Nice rep manipulation

I believe you need to add a bracket around it.

map = Maps[math.random(1, #Maps)]

Source

3 comments

1

still got trouble with sky

1

Odd can you send a screenshot of the errors please :)

1

Can't do screenshots as my screenshot software is updating also my prntscrn button broke but i get the error.. ServerScriptService.MapChooser.Selector:14: attempt to index number with 'Sky'

The Map.Sky.Parent = game.Lighting is probably wrong. Maybe you should change it to Map.Sky.Parent = game:GetService("Lighting") .

3 comments

0

If there still errors, comment below, thanks too:)

1

That's not what the error is about...

1

Still got error

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