-
What does the code do and what are you not satisfied with? - The code is supposed to pick a map with map voting.
-
What potential improvements have you considered? - Using something else than using a lot of if and elseif statements.
-
How (specifically) do you want to improve the code? - Make the code more efficient and take up less space.
local MapModule = {}
MapModule.Maps = {}
function MapModule.PickMap()
for I, V in pairs(MapModule.Maps) do
table.remove(MapModule.Maps, I)
end
local Rand = Random.new()
local Maps = game:GetService("ServerStorage").Maps:GetChildren()
local RandomMap1 = Maps[Rand:NextInteger(1, 3)]
local RandomMap2 = Maps[Rand:NextInteger(4, 5)]
local RandomMap3 = Maps[Rand:NextInteger(6, 7)]
table.insert(MapModule.Maps, 1, RandomMap1:Clone())
table.insert(MapModule.Maps, 2, RandomMap2:Clone())
table.insert(MapModule.Maps, 3, RandomMap3:Clone())
game:GetService("ReplicatedStorage").MapPick:FireAllClients(RandomMap1.Name, RandomMap2.Name, RandomMap3.Name)
return RandomMap1, RandomMap2, RandomMap3
end
function MapModule.PlaceMap()
if game:GetService("ReplicatedStorage").Map1Vote.Value > game:GetService("ReplicatedStorage").Map2Vote.Value and game:GetService("ReplicatedStorage").Map3Vote.Value then
for _, V in pairs(MapModule.Maps[1]:GetChildren()) do
V.Parent = workspace.Props
end
return
elseif game:GetService("ReplicatedStorage").Map2Vote.Value > game:GetService("ReplicatedStorage").Map1Vote.Value and game:GetService("ReplicatedStorage").Map3Vote.Value then
for _, V in pairs(MapModule.Maps[2]:GetChildren()) do
V.Parent = workspace.Props
end
return
elseif game:GetService("ReplicatedStorage").Map3Vote.Value > game:GetService("ReplicatedStorage").Map2Vote.Value and game:GetService("ReplicatedStorage").Map1Vote.Value then
for _, V in pairs(MapModule.Maps[3]:GetChildren()) do
V.Parent = workspace.Props
end
return
elseif game:GetService("ReplicatedStorage").Map1Vote.Value == game:GetService("ReplicatedStorage").Map2Vote.Value then
local RandomNumber = math.random(1, 2)
for _, V in pairs(MapModule.Maps[RandomNumber]:GetChildren()) do
V.Parent = workspace.Props
end
return
elseif game:GetService("ReplicatedStorage").Map2Vote.Value == game:GetService("ReplicatedStorage").Map3Vote.Value then
local RandomNumber = math.random(2, 3)
for _, V in pairs(MapModule.Maps[RandomNumber]:GetChildren()) do
V.Parent = workspace.Props
end
return
elseif game:GetService("ReplicatedStorage").Map1Vote.Value == game:GetService("ReplicatedStorage").Map3Vote.Value then
local RandomNumber = math.random(0, 2)
for _, V in pairs(MapModule.Maps[RandomNumber + 1]:GetChildren()) do
V.Parent = workspace.Props
end
return
end
if game:GetService("ReplicatedStorage").Map3Vote.Value == 0 and game:GetService("ReplicatedStorage").Map1Vote.Value == 0 and game:GetService("ReplicatedStorage").Map2Vote.Value == 0 then
local Maps = game:GetService("ServerStorage").Maps:GetChildren()
local Rand = Random.new()
local RandomMap = Maps[Rand:NextInteger(1, #MapModule.Maps)]
for _, V in pairs(RandomMap:GetChildren()) do
V.Parent = workspace.Props
end
return
else
local Maps = game:GetService("ServerStorage").Maps:GetChildren()
local Rand = Random.new()
local RandomMap = Maps[Rand:NextInteger(1, #Maps)]
for _, V in pairs(RandomMap:Clone():GetChildren()) do
V.Parent = workspace.Props
end
end
end
function MapModule.DeleteMap()
for _, V in pairs(workspace.Props:GetChildren()) do
V:Destroy()
end
end
return MapModule
Thanks for your time.