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

How would you make a map randomizer vote script?

I need help with this I dont understand.

2 answers

Well when randomizing maps, we will obviously need a few things.

  1. A table/list of all the maps, primarily in one model if possible

  2. We will need to use the math.random function from lua's math library.

  3. We will need to store the new map into a variable that can be referenced to later on.

So simply:

--"model" is the storage place for all the maps,
--GetChildren simply turns it into a table
--This is equilavent to local maps = {workspace.map1, workspace.map2}
local maps = model:GetChildren()

--In order to get a value from the table, we must index it this way:
--table[index]
-- tab = {"hi"} print(tab[1]) --> "hi"
--Lua tables start at 1 so we use 1 as the first argument in math.random which is the minimum value, and #maps as the second argument since it returns the amount of objects in the table
local chosenMap = maps[math.random(1, #maps)]

print(chosenMap.Name) --If the chosenMap existed, it would print the name

If you want to learn more:

GetChildren()'

math.random()

Tables

--Edit

Extra Notes:

If you want a vote script, you will need to ask that as a whole different question. However, for randomizing, you will need to run the above script as much as you want. As a little help, I will teach you how to gather 3 different maps that the players will have to choose from.

local maps = model:GetChildren()

local chosenMap1 = maps[math.random(1, #maps)]

--This will get a random map but will only continue if the map is different from the chosenMap1
repeat
chosenMap2 = maps[math.random(1, #maps)]
until
chosenMap2 ~= chosenMap1

--Repeat the same procedure for chosenMap3

repeat
chosenMap3 = maps[math.random(1, #maps)]
until
chosenMap3 ~= chosenMap2 and chosenMap3 ~= chosenMap1

--Now the more maps you have, the more conditionals you will be have to check for.

print(chosenMap1.Name)
print(chosenMap2.Name)
print(chosenMap3.Name)

--These should all print different names, unless you exceed the number of maps you currently have

--Just for pattern sake, here is for a 4th random map

repeat
chosenMap4 = maps[math.random(1, #maps)]
until
chosenMap4 ~= chosenMap3 and chosenMap4 ~= chosenMap2 and chosenMap4 ~= chosenMap1

--Notice the more maps I want, the more checking I have to do for the other maps

print(chosenMap4.Name)

--If you really have 4 maps or more, this will print a different name from the rest

For more information on repeat, read this

Why is everyone giving me negatives for asking... I'm just trying to understand how...

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