Hello. I am trying to make a Voting System. When the voting time ends it was supposed to pick up a random player to be the monster. But when the voting time reaches to zero in the gui, it continues to -1, -2, etc.
local players
local selectedlocal debounce = true
function check(text)
repeat
wait(0.1)
until debounce == true
debounce = false
script.Parent.Text = text
wait(3)
debounce = true
endgame.ReplicatedStorage.Time.Changed:Connect(function()
if debounce == true then
script.Parent.Text = game.ReplicatedStorage.Manager.Value…" ("…game.ReplicatedStorage.Time.Value…")"
if game.ReplicatedStorage.Time.Value == 0 then do
wait(1)
script.Parent.Text = "The Mystery/MonsterName is " … selected
end
end
end
end)game.ReplicatedStorage.NotEnoughPlayers.OnClientEvent:Connect(function()
if debounce == true then
debounce = false
script.Parent.Text = “Waiting for more players…”
wait(3)
debounce = true
else
local text = “Waiting for more players…”
check(text)
endend)
game.ReplicatedStorage.SendTextToPlayers.OnClientEvent:Connect(function(text)
if debounce == true then
debounce=false
script.Parent.Text = text
wait(3)
debounce=true
else
check(text)
end
end)–Get Random Player:
local function selectPlayer()
players = game.Players:GetPlayers()
selected = players[math.random(1,#players)]
return selected
endif game.ServerScriptService.VotingSystem.Script.Script2.LobbyTime == 0 then do
wait (0.5)
selectPlayer()
end
end
Is there anyone who can explain to me why is this happening?