Hello!
I am currently trying to make a Round System where players can vote for different maps in my game however the client doesn’t receive the data I send from the server as seen in the output below:
, If someone would like to review my code here it is below:
Server Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local VoteEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("RemoteEvents"):WaitForChild("VoteEvent")
local MapsFolder = ServerStorage:WaitForChild("Maps")
local MapVotes = {}
local MapChoices = {}
local function chooseMapsForVoting()
local allMaps = MapsFolder:GetChildren()
MapChoices = {}
MapVotes = {}
if #allMaps < 3 then
warn("Not enough maps in MapsFolder for voting")
return
end
for i = 1, 3 do
local randomMap = allMaps[math.random(1, #allMaps)]
if randomMap then
table.insert(MapChoices, randomMap)
MapVotes[randomMap.Name] = 0
else
warn("Random map selection failed. Map is nil.")
end
end
end
local function startVoting()
chooseMapsForVoting()
if #MapChoices < 3 then
warn("Not enough valid map choices for voting")
return
end
print("Sending map choices to clients: ", MapChoices)
VoteEvent:FireAllClients(MapChoices)
end
while true do
startVoting()
task.wait(10)
end
Local Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local VoteEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("RemoteEvents"):WaitForChild("VoteEvent") -- Ensure the VoteEvent exists
local VotingGui = script.Parent.VotingGui
local Button1 = VotingGui:WaitForChild("Map1Button")
local Button2 = VotingGui:WaitForChild("Map2Button")
local Button3 = VotingGui:WaitForChild("Map3Button")
local function startVoting(mapChoices)
VotingGui.Visible = true
print("Client Has Received:")
print(mapChoices)
if not mapChoices or #mapChoices < 3 then
warn("Invalid map choices received from server")
VotingGui.Visible = false
return
end
if mapChoices[1] then
Button1.Text = mapChoices[1].Name
else
warn("Map1 is nil")
end
if mapChoices[2] then
Button2.Text = mapChoices[2].Name
else
warn("Map2 is nil")
end
if mapChoices[3] then
Button3.Text = mapChoices[3].Name
else
warn("Map3 is nil")
end
Button1.MouseButton1Click:Connect(function()
if mapChoices[1] then
VoteEvent:FireServer(mapChoices[1].Name)
end
VotingGui.Visible = false
end)
Button2.MouseButton1Click:Connect(function()
if mapChoices[2] then
VoteEvent:FireServer(mapChoices[2].Name)
end
VotingGui.Visible = false
end)
Button3.MouseButton1Click:Connect(function()
if mapChoices[3] then
VoteEvent:FireServer(mapChoices[3].Name)
end
VotingGui.Visible = false
end)
end
-- Listen for the server to send voting options
VoteEvent.OnClientEvent:Connect(function(mapChoices)
startVoting(mapChoices)
end)
Any Comments would be kindly appreciated