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

What is wrong with this map chosing script?

Asked by
Mystdar 352 Moderation Voter
10 years ago

This is a Normal Script in the Workspace Just so you know, 'Lifter' is supposed to be a block that lifts the players off the ground, so the map can change.

01Maps = {Map1, Map2, Map3}
02Colours = {BrickColor.new("Black"), BrickColor.new("Really Black"), BrickColor.new("Really Red")}
03 
04Event = game.Workspace.Event
05Map = script.Parent.Map
06 
07function SelectMap()
08    a = math.random(1,#Maps)-- Select a random Map
09    -- print a
10    if a == Map1 then
11        b = game.Lighting.Map1:Clone()
12        b.Parent = Workspace
13        b:MoveTo(Vector3.new(0, 0, 0))
14        b.Name = "Map"
15        Map.Value = 1
View all 68 lines...

Thank you in advance

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

SelectMap()

You haven't defined Map1, Map2, or Map3.

That means your definition of Maps is equivalent to

1Maps = {nil, nil, nil}

This will also cause #Maps to be 0.


Use strings for Maps:

1Maps = {"Map1", "Map2", "Map3"}

In addition, even if the above was fixed, your code still wouldn't work.

Your checks are comparing a and "Map1" -- but a is just a random number, which isn't ever one of the map names.

You should be looking at Maps[a], that is, the ath thing in Maps.


All this simplifies your work in SelectMap: good code should not care about how many / which are the maps that are in your list -- the information it needs should be good enough by just inspecting Maps:

1function SelectMap()
2    a = math.random(1,#Maps)
3    -- print a
4    b = game.Lighting[Maps[a]]:Clone() -- Use the name Maps[a]
5    b.Parent = Workspace
6    b:MoveTo(Vector3.new(0, 0, 0))
7    b.Name = "Map"
8    Map.Value = a
9end -- Ending SelectMap

Lifter()

Size is a Vector3, not a CFrame.

It's much cleaner and easier to understand

1d.Size = Vector3.new(10, i, 10)

over

1d.Size = d.Size + Vector3.new(0, 1, 0)

(In your original code, you used x, y, and z but never defined them)

Both of these comments go for Position too -- except that you should be using the CFrame property, not Position.


There isn't a better way to wait in minutes, but it might be cleaner to say

1wait(10 * 60)

because then it's clearer where the number 600 came from (it's obviously 10 * 60seconds = 10 minutes)

0
Is position also Vector3? Because in your improved SelectMap script you used Vector3 for Postion on line 6, I believe Mystdar 352 — 10y
0
Also do you know why only the first one spawns at the right position? Afterwards the second one spawns but +the height of the one underneath, do you know why? Mystdar 352 — 10y
0
Position is a Vector3. First what spawns? BlueTaslem 18071 — 10y
0
One of the maps then after 10 seconds (I shorterned for testing) The other one spawns above the first one. Mystdar 352 — 10y
0
I have edited the above code with a DownLifter function (To make it go back down again) Can I edit the above code, or shall I post it as a new question? Mystdar 352 — 10y
Ad

Answer this question