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.
Maps = {Map1, Map2, Map3} Colours = {BrickColor.new("Black"), BrickColor.new("Really Black"), BrickColor.new("Really Red")} Event = game.Workspace.Event Map = script.Parent.Map function SelectMap() a = math.random(1,#Maps)-- Select a random Map -- print a if a == Map1 then b = game.Lighting.Map1:Clone() b.Parent = Workspace b:MoveTo(Vector3.new(0, 0, 0)) b.Name = "Map" Map.Value = 1 elseif a == Map2 then c = game.Lighting.Map2:Clone() c.Parent = Workspace c:MoveTo(Vector3.new(0, 0, 0)) c.Name = "Map" Map.Value = 2 elseif a == Map3 then c = game.Lighting.Map3:Clone() c.Parent = Workspace c:MoveTo(Vector3.new(0, 0, 0)) c.Name = "Map" Map.Value = 3 end -- Ending ifs end -- Ending SelectMap function Lifter() d = Instance.new("Part") d.Parent = Workspace d.Position = Vector3.new(0, 0, 0) d.BrickColor = Colours[1] -- Sorry if that confuses anyone with Colors and Colours d.Size = CFrame.new(10, 1, 10) for i = 1, 10 do d.Size = CFrame.new(x, y+1, z) -- Make it taller -- Not sure if when adding 1 to a part it adds 0.5 to both sides or one to -- the top of the block, I want it to add one to the top of the block -- I think it does the first one which is why this next line exists d.Position = Vector3.new(x, y+0.5, z) -- While the bottom stays in the same position end end function NewMap() wait (600) -- 10 Minutes (Tell me if there is a better way to wait in minutes) if Event.Value == "None" then Lifter() game.Workspace.Map:remove() SelectMap() else wait(Event.Value == "None") Lifter() game.Workspace.Map:remove() SelectMap() end -- End the ifs end -- End New maps -- There is probably a far better way to do this next part -- In fact there is probably a far better way to do most of this, which is why i'm here! SelectMap() -- First time the game loads select a map -- Then forever go through the map chosing cycle MUHAHAHAH!! I'm evil >:D while true do NewMap() end
Thank you in advance
You haven't defined Map1
, Map2
, or Map3
.
That means your definition of Maps
is equivalent to
Maps = {nil, nil, nil}
This will also cause #Maps
to be 0
.
Use strings for Maps
:
Maps = {"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 a
th 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
:
function SelectMap() a = math.random(1,#Maps) -- print a b = game.Lighting[Maps[a]]:Clone() -- Use the name Maps[a] b.Parent = Workspace b:MoveTo(Vector3.new(0, 0, 0)) b.Name = "Map" Map.Value = a end -- Ending SelectMap
Size
is a Vector3
, not a CFrame
.
It's much cleaner and easier to understand
d.Size = Vector3.new(10, i, 10)
over
d.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
wait(10 * 60)
because then it's clearer where the number 600
came from (it's obviously 10 * 60seconds = 10 minutes)