I have a GUI which has a certain player pick 4 players to compete in a challenge, which works on the first loop game loop (this is a while loop). The GUI system works perfectly throughout the entire game but when the game starts a new round (second loop and onward) it only lets a player pick one player and then it randomizes the rest of the options. I’m not sure on why this is occurring because there is not errors in the output.
–ServerScript:
--Player picking screen
--Send picking gui
for i, player in pairs(thronePlayer) do
voteEVENT:FireClient(player, contestants)
end
--Recieve the votes
EliminationPlayers = {}
function recievevote(i, player)
player = game.Players[player]
if table.find(EliminationPlayers, player) == nil then
table.insert(EliminationPlayers, player)
end
if #EliminationPlayers == 4 then
for i, v in pairs(thronePlayer) do
voteguiEVENT:FireClient(v)
end
end
end
voteEVENT.OnServerEvent:Connect(recievevote)
local Judgement = 20
GuiStat.Value = "Judgement"
repeat
Judgement = Judgement - 1
Timer.Value = (Judgement)
wait(1)
until Judgement == 0 or #EliminationPlayers == 4
for i, v in pairs(thronePlayer) do
voteguiEVENT:FireClient(v)
end
--Put the current picked players in a table
local index = 1;
while contestants[index] do
local didRemove = false
for i,plr in pairs(EliminationPlayers) do
if contestants[index] == plr then
table.remove(contestants,index)
didRemove = true
break
end
end
if didRemove == false then
index = index + 1
end;
end
---Check if there is less than 4 players, if there is put them in a table
local autoELIM = false
if #EliminationPlayers < 4 then
autoELIM = true
repeat
elimpick = math.random(1, #contestants)
pickedelim = contestants[elimpick]
table.insert(EliminationPlayers, pickedelim)
table.remove(contestants, elimpick)
until #EliminationPlayers == 4
end
--moving picked players into eliminationplayers table
if autoELIM == false then
local index = 1;
while contestants[index] do
local didRemove = false
for i,plr in pairs(EliminationPlayers) do
if contestants[index] == plr then
table.remove(contestants,index)
didRemove = true
break
end
end
if didRemove == false then
index = index + 1
end;
end
else
autoELIM = false
end
–Local Script
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)