The issue is the variable picked inside of if amountOfMaps comes out as nil when referenced outside of the script but all of the other variables picked come out as they should. I am very lost and would appreciate any help. Thank you.
if amountOfMaps >= 1 then
local picked = mapsInQueueCheck[math.random(1, #mapsInQueueCheck)]
local playerPurchased = picked.Value
local name = picked.Name
print(playerPurchased)
print(picked)
status.Value = playerPurchased.." picked "..name.."!"
wait(5)
end
if amountOfMaps == 0 then
local mostVotes = 0
for i, v in pairs(votedMaps) do
local number = tonumber(v)
if number > mostVotes then
mostVotes = number
end
end
if mostVotes == 0 then
status.Value = "No maps Voted!"
wait(5)
picked = mapVotingOptions[math.random(1, #mapVotingOptions)]
status.Value = "Random Map: "..picked
else if mostVotes > 0 then
if voteMapOne.Value == mostVotes then
picked = table.concat(mapVotingOptions,'',1,1)
status.Value = picked.." had the most votes!"
end
if voteMapTwo.Value == mostVotes then
picked = table.concat(mapVotingOptions,'',2,2)
status.Value = picked.." had the most votes!"
end
if voteMapThree.Value == mostVotes then
picked = table.concat(mapVotingOptions,'',3,3)
status.Value = picked.." had the most votes!"
end
end
end
end
game.ReplicatedStorage.MapEvents.votingTriggers.closeVoting:FireAllClients()
print(picked)
local randMap = Maps:FindFirstChild(picked)