Hello guys! I’m currently having problems with the voting system that was made by my friend.
When the voting starts, the voting doesnt appears, and this appears in the dev console:
And yes, I did check if MapPictureID exists.
I don’t know but I think that just happens in the experience in Roblox, Not on Roblox studio.
Script that gave the error:
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Maps = ServerStorage:WaitForChild('Maps'):GetChildren()
local VoteEvents = ReplicatedStorage.VoteEvents
local Status = ReplicatedStorage:WaitForChild('Status')
local Votes = {}
local function GetMapModelWithMapDataMap(MapData)
print(MapData)
local Map = ServerStorage.Maps:FindFirstChild(MapData.Name)
return Map
end
local function GetMapWithMoreVotes()
print(Votes)
-- Returns the map with the most votes, or a random one if all are 0
local MapWithMoreVotes = nil
local HighestVotes = 0
for i, Map in Votes do
local VotesValue = Map.Votes
if VotesValue and VotesValue > HighestVotes then
MapWithMoreVotes = Map
HighestVotes = VotesValue
end
end
-- If all maps have 0 votes or no votes were cast, pick a random map from Votes
if MapWithMoreVotes == nil then
MapWithMoreVotes = Votes[math.random(1, 3)] -- 3 (max maps)
end
return MapWithMoreVotes
end
local function ConvertToRandomMapsData(RandomMaps)
local RandomMapsData = {}
for i, Map in ipairs(RandomMaps) do
if Map and Map.Votes and Map.MapPictureID then
table.insert(RandomMapsData, {Name = Map.Name, Votes = Map.Votes.Value, MapPictureID = Map.MapPictureID.Value})
else
return
end
end
Votes = RandomMapsData
return RandomMapsData
end
VoteEvents.PlayerVote.OnServerEvent:Connect(function(PlayerWhoVoted, MapName, index)
local MapData = Votes[index]
MapData.Votes = MapData.Votes + 1
VoteEvents.UpdateVoteCount:FireAllClients(MapName, MapData)
print(MapData)
end)
VoteEvents.RemoveVoteCount.OnServerEvent:Connect(function(Player, index)
local MapData = Votes[index]
MapData.Votes = MapData.Votes - 1
end)
while true do
-- Clean up any leftover "Votes" NumberValues from all maps before starting a new round
for i, map in Maps do
local oldVotes = map:FindFirstChild("Votes")
if oldVotes then
oldVotes:Destroy()
end
end
Votes = {} -- Reset the Votes
-- Intermission
local Countdown = 15
workspace.music.SoundId = "rbxassetid://131736922566985"
workspace.music:Play()
Status.Parent.Map.Value = ""
repeat task.wait(1)
Countdown = Countdown - 1
Status.Value = 'Intermission: '..Countdown
until Countdown <= 0
-- Vote Time
Status.Value = 'Voting Time'
local RandomMaps = {}
for i = 1, 3 do
local RandomMap = Maps[math.random(1,#Maps)]
while table.find(RandomMaps, RandomMap) do
RandomMap = Maps[math.random(1,#Maps)]
end
local NumberValue = Instance.new("NumberValue", RandomMap)
NumberValue.Name = "Votes"
table.insert(RandomMaps, RandomMap)
end
local RandomMapsData = ConvertToRandomMapsData(RandomMaps)
print(RandomMapsData) -- Print the RandomMapsData Table
VoteEvents.VoteTime:FireAllClients(RandomMapsData)
task.wait(15) -- Voting Time
VoteEvents.VoteEnd:FireAllClients()
local MapWithMoreVotes = GetMapWithMoreVotes()
local ChosenMap = GetMapModelWithMapDataMap(MapWithMoreVotes)
-- Load Map
task.wait(1)
ChosenMap.Parent = workspace
Status.Value = 'Selected map: '..ChosenMap.Name
Status.Parent.Map.Value = ChosenMap.Name
task.wait(2)
Countdown = 171 -- Game Time
workspace.music.SoundId = "rbxassetid://78753868115672"
workspace.music:Play()
repeat task.wait(1)
Countdown = Countdown - 1
Status.Value = 'Time left: '..Countdown
until Countdown <= 0
-- Kill the players
for i, Player in pairs(Players:GetPlayers()) do
if Player.Character and Player.Character:FindFirstChild('Humanoid') then
Player.Character.Humanoid:TakeDamage(2000)
end
end
ChosenMap:Destroy()
-- Clean up "Votes" NumberValues from all maps after the round
for i, map in Maps do
local oldVotes = map:FindFirstChild("Votes")
if oldVotes then
oldVotes:Destroy()
end
end
Status.Value = 'da round ended now wait for intermission start >:('
task.wait(1) -- little pause, make this as long as you want.
end
