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

Would these random map variables work?

Asked by 10 years ago

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

Log in to vote
1
Answered by 10 years ago

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! :)

0
Great, thanks! SlickPwner 534 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

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
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? SlickPwner 534 — 10y
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. XanthicDragon 38 — 10y

Answer this question