Votes not showing up on ui

Hello, I have two scripts, one server side, one client side and two remote events (VoteEvent, VoteCountEvent)

The script is for a minigame where you vote on a map and it displays the votes then teleports you, but it isnt displaying the votes and somethings wrong, can you tell me how to fix it? Ive tried everything.

Client Side:

-- Client-Side Script (LocalScript)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local VoteEvent = ReplicatedStorage:WaitForChild("VoteEvent")
local VoteCountEvent = ReplicatedStorage:WaitForChild("VoteCountEvent")

-- UI elements
local frame = script.Parent
local votingUI = frame.votingUI
local button1 = script.Parent.Button1
local button2 = script.Parent.Button2
local mapNameLabel1 = script.Parent.MapNameLabel1
local mapNameLabel2 = script.Parent.MapNameLabel2
local voteCountLabel1 = script.Parent.VoteCountLabel1
local voteCountLabel2 = script.Parent.VoteCountLabel2

local function UpdateUI(voteCounts)
	-- Find the map options with the highest vote counts
	local maxVotes1 = 0
	local maxVotes2 = 0
	local winningMapOption1
	local winningMapOption2

	for mapOption, voteCount in pairs(voteCounts) do
		if voteCount > maxVotes1 then
			maxVotes1 = voteCount
			winningMapOption1 = mapOption
		elseif voteCount > maxVotes2 then
			maxVotes2 = voteCount
			winningMapOption2 = mapOption
		end
	end

	-- Update the UI with the winning map options and their vote counts
	mapNameLabel1.Text = winningMapOption1 or "No votes"
	voteCountLabel1.Text = "Votes: " .. tostring(maxVotes1)
	print("Votes:"..tostring(maxVotes1))

	mapNameLabel2.Text = winningMapOption2 or "No votes"
	voteCountLabel2.Text = "Votes: " .. tostring(maxVotes2)
	print("Votes:"..tostring(maxVotes2))
	
end

VoteCountEvent.OnClientEvent:Connect(UpdateUI)

Server-Side:

-- Server-Side Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local VoteEvent = Instance.new("RemoteEvent")
VoteEvent.Name = "VoteEvent"
VoteEvent.Parent = ReplicatedStorage

local VoteCountEvent = Instance.new("RemoteEvent")
VoteCountEvent.Name = "VoteCountEvent"
VoteCountEvent.Parent = ReplicatedStorage

local mapVotes = {}

local function CastVote(player, mapOption)
	print("Received vote event:", mapOption)
	if not mapVotes[mapOption] then
		mapVotes[mapOption] = 0
	end
	mapVotes[mapOption] = mapVotes[mapOption] + 1

	VoteCountEvent:FireAllClients(mapVotes)  -- Send updated vote counts to all clients
end

VoteEvent.OnServerEvent:Connect(CastVote)

local function DetermineWinningMap()
	local winningMap
	local maxVotes = 0

	for mapOption, voteCount in pairs(mapVotes) do
		if voteCount > maxVotes then
			maxVotes = voteCount
			winningMap = mapOption
		end
	end

	return winningMap
end

local function TeleportPlayersToMap(mapOption)
	local mapPart = game.Workspace:FindFirstChild(mapOption)
	if mapPart and mapPart:IsA("Part") then
		for _, player in ipairs(Players:GetPlayers()) do
			player.Character:MoveTo(mapPart.Position)
		end
	else
		warn("Map part not found for map option:", mapOption)
	end
end

local function ResetVoteCounts()
	local emptyVoteCounts = {}
	for mapOption, _ in pairs(mapVotes) do
		emptyVoteCounts[mapOption] = 0
	end

	mapVotes = emptyVoteCounts
	VoteCountEvent:FireAllClients(mapVotes)  -- Send empty vote counts to reset the UI on all clients
end


while true do
	ResetVoteCounts()
	wait(15)  -- Adjust the voting time as needed

	local winningMap = DetermineWinningMap()

	if winningMap then
		TeleportPlayersToMap(winningMap)
	end

	ResetVoteCounts()
end

Thank you

2 Likes