I’m facing a problem: The amount of times I call my function is the amount of times it would call the remoteevent. Example - function is called once at the end of one round it would increment the value by 1, function is called once at the end of another round it would increment the value by 2.
I tried adding a debounce, re-arranging the code, and messing when the round system calls the function.
Help would be appreciated!
The function!
function vote()
if Values.Playable.Value == false then
Values.VotingTime.Value = true
Remotes.enableVoting:FireAllClients()
Remotes.Mapvote.OnServerEvent:Connect(function(plr,objClickedName)
if Values.VotingTime.Value then
print("Voted for map")
onClientClick(objClickedName)
Remotes.displayGamemodeGUI:FireClient(plr)
end
end)
print("Step 7,8")
Remotes.GamemodeVote.OnServerEvent:Connect(function(plr,objClickedName)
if Values.VotingTime.Value then
print("Voted for gamemode")
onClientClickGamemode(objClickedName)
Remotes.removeVotingGui:FireClient(plr)
end
end)
for i = 10, 0,-1 do
wait(1)
if i < 1 then
Values.VotingTime.Value = false
break
end
end
end
nono more isnt the problem i need less giving a million lines of code will just put people off trying to solve it just narrow it down a bit and give a clearer explanation like saving a value gets incremeted you need to show which value (but that isnt the main concern anyway)
You could do that, as that’s an easier solution, but for future reference:
local connection1
local connection2
function vote()
if connection1 then
connection1:Disconnect() -- disconnect the old events
end
if connection2 then
connection2:Disconnect()
end
if Values.Playable.Value == false then
Values.VotingTime.Value = true
Remotes.enableVoting:FireAllClients()
connection1 = Remotes.Mapvote.OnServerEvent:Connect(function(plr,objClickedName)
-- connect the variables to the events
if Values.VotingTime.Value then
print("Voted for map")
onClientClick(objClickedName)
Remotes.displayGamemodeGUI:FireClient(plr)
end
end)
print("Step 7,8")
connection2 = Remotes.GamemodeVote.OnServerEvent:Connect(function(plr,objClickedName)
if Values.VotingTime.Value then
print("Voted for gamemode")
onClientClickGamemode(objClickedName)
Remotes.removeVotingGui:FireClient(plr)
end
end)
for i = 10, 0,-1 do
wait(1)
if i < 1 then
Values.VotingTime.Value = false
break
end
end
end