So I’m trying to make a map voting system and I have it mapped out pretty well where it chooses 3 random maps to get put up for voting. But however when it’s time to vote when one player votes the other players get an error message on the
buttonVoteInstance.Votes.Votes.Value += 1
in the client script?
Client:
Map1Button.MouseButton1Click:Connect(function()
if Map1Button.Active == true then
disableAllButtons()
voteScoreEvent:FireServer(Map1Button)
end
end)
Map2Button.MouseButton1Click:Connect(function()
if Map2Button.Active == true then
disableAllButtons()
voteScoreEvent:FireServer(Map2Button)
end
end)
Map3Button.MouseButton1Click:Connect(function()
if Map3Button.Active == true then
disableAllButtons()
voteScoreEvent:FireServer(Map3Button)
end
end)
voteScoreEventClient.OnClientEvent:Connect(function(buttonVoteInstance)
buttonVoteInstance.Votes.Votes.Value += 1
buttonVoteInstance.Votes.Text = tostring(buttonVoteInstance.Votes.Votes.Value)
end)
Server:
local randomMap1 = math.random(1, #maps)
local mapInstance1 = maps[randomMap1]
table.remove(maps, randomMap1)
local randomMap2 = math.random(1, #maps)
local mapInstance2 = maps[randomMap2]
table.remove(maps, randomMap1)
local randomMap3 = math.random(1, #maps)
local mapInstance3 = maps[randomMap3]
table.remove(maps, randomMap1)
wait(10)
votingEvent:FireAllClients(mapInstance1, mapInstance2, mapInstance3)
voteScoreEvent.OnServerEvent:Connect(function(player, buttonVoteInstance)
voteScoreEventClient:FireAllClients(buttonVoteInstance)
end)
You can’t send through the buttons. Each player’s UI is different, by sending the button, you’re sending through the specific UI object for the player that voted.
Send through button names instead and then grab the local button to update.
Psuedocode:
local votes = {}
fireserver(buttonName)
onserverevent(buttonName)
if not votes[buttonName] then votes[buttonName] = 0 end
votes[buttonName] += 1
guiParent[buttonName].Text = votes[buttonName]
end)
No, you have to pass the name through the remote event. The GUI does not exist for other players!
Do this!
Client
Map1Button.MouseButton1Click:Connect(function()
if Map1Button.Active == true then
disableAllButtons()
voteScoreEvent:FireServer(Map1Button.Name)
end
end)
Map2Button.MouseButton1Click:Connect(function()
if Map2Button.Active == true then
disableAllButtons()
voteScoreEvent:FireServer(Map2Button.Name)
end
end)
Map3Button.MouseButton1Click:Connect(function()
if Map3Button.Active == true then
disableAllButtons()
voteScoreEvent:FireServer(Map3Button.Name)
end
end)
voteScoreEventClient.OnClientEvent:Connect(function(buttonVoteName)
local buttonInstance = script.Parent:FindFirstChild(buttonVoteName)
if not buttonInstance then return end
buttonInstance.Votes.Votes.Value += 1
buttonInstance.Votes.Text = tostring(buttonInstance.Votes.Votes.Value)
end)
Server
local randomMap1 = math.random(1, #maps)
local mapInstance1 = maps[randomMap1]
table.remove(maps, randomMap1)
local randomMap2 = math.random(1, #maps)
local mapInstance2 = maps[randomMap2]
table.remove(maps, randomMap1)
local randomMap3 = math.random(1, #maps)
local mapInstance3 = maps[randomMap3]
table.remove(maps, randomMap1)
wait(10)
votingEvent:FireAllClients(mapInstance1, mapInstance2, mapInstance3)
voteScoreEvent.OnServerEvent:Connect(function(player, buttonVoteName)
voteScoreEventClient:FireAllClients(buttonVoteName)
end)