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

What is wrong with this map chosing script?

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

1 answer

SelectMap()

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

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

Lifter()

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)

5 comments

0

Is position also Vector3? Because in your improved SelectMap script you used Vector3 for Postion on line 6, I believe

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?

0

Position is a Vector3. First what spawns?

0

One of the maps then after 10 seconds (I shorterned for testing) The other one spawns above the first one.

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?

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