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

Would these random map variables work?

I've set a few random map variables, and I'm not sure if the clone one is correct, but I don't know enough about it to find out. Can someone help?

		local maps = {Map1, Map2, Map3, Map4, Map5}
		local randomMap = math.random(1,#maps)
		clone = game.Lighting..randomMap:clone()

2 answers

✓ Accepted answer

There's a few things wrong with this: First of all, in the 'maps' table you need to add speech marks around the string-values, like this:

local maps = {"Map1", "Map2", "Map3", "Map4", "Map5"}

Then instead of using normal brackets in line 2 use square brackets, and you need to call the table- like so:

local randomMap = maps[math.random(1, #maps)] -- This will call the 'maps' table, and select a random value from it, in this case the map names.

Finally, now you've called a value from the table you can use that- so you would do this:

clone = game.Lighting:FindFirstChild(randomMap):Clone()
clone.Parent = Game.Workspace -- Make sure to set the clones parent.

Now if you put all of that together you should get:

local maps = {"Map1", "Map2", "Map3", "Map4", "Map5"}
local randomMap = maps[math.random(1, #maps)]
clone = game.Lighting:FindFirstChild(randomMap):Clone()
clone.Parent = Game.Workspace -- Make sure to set the clones parent.

This should work, hope it helps! :)

1 comment

0

Great, thanks!

clone works on objects. This means a variable like game.Workspace.Model. You also have to specify the parent of the clone:

clone.Parent = game.Workspace

2 comments

0

Yeah, I have the clone added I just didn't put it in. I named the maps in the lighting "Map1", "Map2", etc, would it work?

0

Ohhh! Okay. Based o what you're doing, all you need to do is add "" around Map1, Map2 and so on in that table then it'll work great.

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