Hey There! I am trying to make a map voting system for my Tower Defense game and I would want a random 3 maps to be pulled out of a folder and placed into my maps frame.
Heres the scripts to be edited
Local Script:
local function SetupVoteGui()
if not info.Voting.Value then
return
end
Gui.Voting.Visible = true
local events = ReplicatedStorage:WaitForChild("Events")
local voteEvent = events:WaitForChild("VoteForMap")
local voteCountUpdate = events:WaitForChild("UpdateVoteCount")
local maps = Gui.Voting.Maps:GetChildren()
for i, button in ipairs(maps) do
if button:IsA("ImageButton") then
button.Activated:Connect(function()
voteEvent:FireServer(button.Name)
end)
end
end
voteCountUpdate.OnClientEvent:Connect(function(mapScores)
for name, voteInfo in pairs(mapScores) do
local button = Gui.Voting.Maps:FindFirstChild(name)
if button then
button.Vote.Text = #voteInfo
end
end
end)
end
Normal Script (Or server side):
function round.ToggleVoting()
local maps = ServerStorage.Maps:GetChildren()
for i, map in ipairs(maps) do
votes[map.Name] = {}
end
info.Voting.Value = true
for i=10, 1, -1 do
info.Message.Value = "Map Voting ("..i..")"
task.wait(1)
end
local winVote = nil
local winScore = 0
for name, map in pairs(votes) do
if #map > winScore then
winScore = #map
winVote = name
end
end
info.Voting.Value = false
return winVote
end
function round.ProcessVote(player, vote)
for name, mapVotes in pairs(votes) do
local oldVote = table.find(mapVotes, player.UserId)
if oldVote then
table.remove(mapVotes, oldVote)
print("Old Vote Found", oldVote)
break
end
end
print("Processed Vote for", vote)
table.insert(votes[vote], player.UserId)
events:WaitForChild("UpdateVoteCount"):FireAllClients(votes)
end
events:WaitForChild("VoteForMap").OnServerEvent:Connect(round.ProcessVote)
local NumberOfPlayers = #game.Players:GetPlayers()
game.Players.PlayerAdded:Connect(function()
NumberOfPlayers = #game.Players:GetPlayers()
end)
All help will be appreciated!