Map Choice Rotation

Hello fellow developers! This is my first post so I may not know how to do a couple things so if I mess up on something please keep an open mind!

Now the problem is that in my game I’m developing isn’t properly working as expected. Heres an example:


Now in the code it is suppost to show random maps inside of a maps folder where I stick all my maps in. But it’ll pick a random map and choose that as all the choices.

I have already tried to look at my code and find an error but I can’t. Please help if you find a solution to the problem!

Now I don’t intend to use this officially though I’m using it to study and learn lua. The video where I figure out how to do this is here:

My code:

This is my Gui
GuiShow

and here is the ReplicatedStorage

ReplicatedStorage

The visible script.

local rep = game:GetService("ReplicatedStorage")
local booleans = rep:WaitForChild("Booleans")
local votingsession = booleans:FindFirstChild("VotingSession")
 
if votingsession.Value == true then
        script.Parent.VotingMapGui.Visible = true
    else
        script.Parent.VotingMapGui.Visible = false
    end
   
votingsession:GetPropertyChangedSignal("Value"):Connect(function()
    if votingsession.Value == true then
        script.Parent.VotingMapGui.Visible = true
    else
        script.Parent.VotingMapGui.Visible = false
    end
end)

Inside each Choice frame is this script.

local player = game:GetService("Players").LocalPlayer
local voted = player:WaitForChild("voted")
local rep = game:GetService("ReplicatedStorage")
local votere = rep:WaitForChild("RemoteEvent"):WaitForChild("Vote")
local variables = rep:WaitForChild("Variables")
local boolean = rep:WaitForChild("Booleans"):WaitForChild("RevealVotes")
local choice = variables:WaitForChild("Choice1")
local votechoice = variables:WaitForChild("VoteChoice1")
local votescounter = script.Parent:FindFirstChild("Votes")
 
local map = choice.Value
    if choice.Value then
    script.Parent.Title.Text = map.Name
    end
choice:GetPropertyChangedSignal("Value"):Connect(function()
    local map = choice.Value
        if choice.Value then
        script.Parent.Title.Text = map.Name
        end
end)
 
if voted.Value == true then
    script.Parent.VOTE.Visible = false
else
    script.Parent.VOTE.Visible = true
end
 
voted:GetPropertyChangedSignal("Value"):Connect(function()
    if voted.Value == true then
        script.Parent.VOTE.Visible = false
    else
        script.Parent.VOTE.Visible = true
    end
end)
 
script.Parent.VOTE.MouseButton1Click:Connect(function()
    votere:FireServer(choice.Name)
end)
 
if boolean.Value == true then
    votescounter.Visible = true
    for i = 1,20 do
        votescounter.Text = "Votes: "..math.random(0,10)
        wait()
    end
    votescounter.Text = "Votes: "..votechoice.Value
else
    votescounter.Visible = false
    votescounter.Text = "Votes: "
end
 
boolean:GetPropertyChangedSignal("Value"):Connect(function()
    if boolean.Value == true then
        votescounter.Visible = true
        for i = 1,20 do
            votescounter.Text = "Votes: "..math.random(0,10)
            wait()
    end
        votescounter.Text = "Votes: "..votechoice.Value
    else
        votescounter.Visible = false
        votescounter.Text = "Votes: "
    end
end)

In ServerScriptService is 4 scripts.

  1. The script called “JoinScript”
local players = game:GetService("Players")
 
players.PlayerAdded:Connect(function(plr)
    local votedvariable = Instance.new("BoolValue",plr)
    votedvariable.Name = "voted"
end)
  1. The script called “RevealScript”
local rep = game:GetService("ReplicatedStorage")
local boolean = rep:WaitForChild("Booleans"):WaitForChild("RevealVotes")
local variables = rep:WaitForChild("Variables")
local voteChoice1 = variables:FindFirstChild("VoteChoice1")
local voteChoice2 = variables:FindFirstChild("VoteChoice2")
local voteChoice3 = variables:FindFirstChild("VoteChoice3")
local winner = variables:FindFirstChild("Winner")
 
 
boolean:GetPropertyChangedSignal("Value"):Connect(function()
    if boolean.Value == true then
        --release the bees!
        local players = game:GetService("Players"):GetPlayers()
       
        for x, player in pairs(players) do
            if player.voted then
                player.voted.Value = true
            end
            wait()
        end
        winner.Value = nil
        local mapvotes = {}
        local biggestone
       
        table.insert(mapvotes,voteChoice1.Value)
        wait()
        table.insert(mapvotes,voteChoice2.Value)
        wait()
        table.insert(mapvotes,voteChoice3.Value)
       
        table.sort(mapvotes)
       
        local biggest = tonumber(mapvotes[#mapvotes])
       
        if biggest == voteChoice1.Value then
            biggestone = variables:FindFirstChild("Choice1")
        end
        if biggest == voteChoice2.Value then
            biggestone = variables:FindFirstChild("Choice2")
        end
        if biggest == voteChoice3.Value then
            biggestone = variables:FindFirstChild("Choice3")
        end
        if biggestone then
        winner.Value = biggestone
        end
    else
        local players = game:GetService("Players"):GetPlayers()
       
        for x, player in pairs(players) do
            if player.voted then
                player.voted.Value = false
            end
            wait()
        end
       
        voteChoice1.Value = 0
        voteChoice2.Value = 0
        voteChoice3.Value = 0
    end
end)
  1. The script called “VoteScript”
local rep = game:GetService("ReplicatedStorage")
local variables = rep:WaitForChild("Variables")
local vote1 = variables:FindFirstChild("VoteChoice1")
local vote2 = variables:FindFirstChild("VoteChoice2")
local vote3 = variables:FindFirstChild("VoteChoice3")
local votere = rep:WaitForChild("RemoteEvent"):WaitForChild("Vote")
 
 
votere.OnServerEvent:Connect(function(plr,choice)
   
    plr:WaitForChild("voted").Value = true
    if choice == "Choice1" then
        vote1.Value = vote1.Value + 1
    elseif choice == "Choice2" then
        vote2.Value = vote2.Value + 1
    elseif choice == "Choice3" then
        vote3.Value = vote3.Value + 1
    end
end)
  1. The script called "MainScript
--torture time
local rep = game:GetService("ReplicatedStorage")
local mapsfolder = game:GetService("Lighting"):WaitForChild("Maps")
 
local booleans = rep:WaitForChild("Booleans")
local variables = rep:WaitForChild("Variables")
local choice1 = variables:FindFirstChild("Choice1")
local choice2 = variables:FindFirstChild("Choice2")
local choice3 = variables:FindFirstChild("Choice3")
local winner = variables:FindFirstChild("Winner")
local timer = 60 --in seconds
 
while true do
while true do
    local maps = mapsfolder:GetChildren()
    choice1.Value = maps[math.random(1,#maps)]
    table.remove(maps,table.find(maps,choice1.Value))
    choice2.Value = maps[math.random(1,#maps)]
    table.remove(maps,table.find(maps,choice2.Value))
    choice3.Value = maps[math.random(1,#maps)]
    table.remove(maps,table.find(maps,choice3.Value))
    wait(1)
    booleans:FindFirstChild("VotingSession").Value = true
    wait(10)
    booleans:FindFirstChild("RevealVotes").Value = true
    wait(5)
    booleans:FindFirstChild("VotingSession").Value = false
    booleans:FindFirstChild("RevealVotes").Value = false
    local chosenmap = winner.Value
   
    if not winner.Value then
        print("Something went wrong!")
        break
    end
    local map = chosenmap.Value
    local clonemap = map:Clone()
   
    print("Getting map...")
    wait(1)
    print("Getting map spawn...")
    if clonemap.Spawn then
        print("Success!")
    else
        print("Task failed successfully")
        wait()
        print("Restarting...")
        clonemap:Destroy()
        break
    end
    clonemap.Parent = workspace
    print("Getting players...")
    local players = game:GetService("Players"):GetPlayers()
    for x, player in pairs(players) do
        local char = player.Character
        if not char then
            print(player.Name.." has no character!")
        else
            local humanoidrootpart = char.HumanoidRootPart
            if not humanoidrootpart then
                print(player.Name.." has no HumanoidRootPart!")
            else
                humanoidrootpart.CFrame = clonemap.Spawn.CFrame + Vector3.new(0,3,0)
            end
        end
        wait()
    end
    for i = timer,0,-1 do
        print(i)
        wait(1)
    end
    for x, player in pairs(players) do
        local char = player.Character
        if not char then
            print(player.Name.." has no character!")
        else
            local humanoidrootpart = char.HumanoidRootPart
            if not humanoidrootpart then
                print(player.Name.." has no HumanoidRootPart!")
            else
                humanoidrootpart.CFrame = workspace.Lobby.SpawnLocation.CFrame + Vector3.new(0,3,0)
            end
        end
        wait()
    end
    clonemap:Destroy()
end
end
4 Likes

Not sure how we’re supposed to help you without any code. :thinking:

1 Like

The video I showed has all the scripts in the desc. And I’m not sure how to do a lot with the text so it would be messy and unreadable.

You can put code on here by doing the following
```lua
–code
```

2 Likes

Thanks! Ill edit the message to add the code. It’s a lot.

I figured all of it out myself