-
What do you want to achieve?
I have a GUI which has a certain player pick 4 players to compete in a challenge, which works on the first loop, however on the second loop it will put a player chosen from the GUI twice and on the third loop three times and so on. -
What is the issue?
I want the GUI to only send the player once to the main script and insert them into the “Elimination Players Table” once however after the first loop it will send a player multiple times. -
What solutions have you tried so far?
I have tried disconnecting the remote Event after the first loop with the lines
local connection = voteEVENT.OnServerEvent:Connect(recievevote)
connection:Disconnect()
However, this doesn’t work for some reason and its placed at the bottom of my loop.
More code to help showcase what I was doing-
Serverscript-
EliminationPlayers = {}
function recievevote(i, player)
player = game.Players[player]
table.insert(EliminationPlayers, player)
if #EliminationPlayers == 4 then
for i, v in pairs(thronePlayer) do
voteguiEVENT:FireClient(v)
end
end
end
voteEVENT.OnServerEvent:Connect(recievevote)
Local Script in the GUI
function voteupdate(contestants)
local avaliableBTNS = script.Parent.Frame:GetChildren()
for i, player in pairs(contestants) do
script.Parent.Enabled = true
open()
local button = avaliableBTNS[1]
button.Visible = true
button.Text = player.Name
button.MouseButton1Down:Connect(function()
voteEVENT:FireServer(button.Text)
button.Visible = false
end)
table.remove(avaliableBTNS, 1)
end
end
function hideVote(v)
close()
script.Parent.Enabled = false
end
voteguiEVENT.OnClientEvent:Connect(hideVote)
voteEVENT.OnClientEvent:Connect(voteupdate)