local StartVotingEvent = VotingEvents.StartVoting
local Maps = {"Camp", "Factory", "Theater"}
function RandomPad1()
--
local RandomMap = Maps[math.random(#Maps)]
MapText1.Text = RandomMap
--
end
function RandomPad2()
--
local RandomMap = Maps[math.random(#Maps)]
MapText2.Text = RandomMap
--
end
function RandomPad3()
--
local RandomMap = Maps[math.random(#Maps)]
MapText3.Text = RandomMap
--
end
StartVotingEvent.Event:Connect(RandomPad1(), RandomPad2(), RandomPad3())
As you can see, I am trying to make a voting system, but when StartVotingEvent is Fired, all three MapText's get randomized and get different names.
But sometimes the names can be the same, for example “MapText1 = Factory, MapText2 = Camp, MapText3 = Factory”
I just want the names to be distributed evenly, no dupes.
Any help is appreciated!
(it’s kind of hard to explain, hopefully i did okay)
local Maps = {"Name1", "Name2", "Name3", ...}
local function GetRandomMap(AvailableMaps: {string})
local Index = math.random(#AvailableMaps)
return Index, AvailableMaps[Index]
end
local function GetThreeRandomMaps()
local AvailableMaps = table.clone(Maps)
local SelectedMaps = {}
for _ = 1, 3 do
local Index: number, Value: string = GetRandomMap(AvailableMaps)
table.remove(AvailableMaps, Index)
table.insert(SelectedMaps, Value)
end
return SelectedMaps
end
Sorry for the late response, but this doesn’t work because the table.remove(Maps, NUMBER) expects a number, not a string. How do you think I should work around this?
Whatever the value is, in this case if it’s the map name you would do string. Though the code I gave you shouldn’t get duplicate maps anyway since it gets removed from the available maps table.