Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How Would You Keep Repeating A Function Until There Is Enough Of Amount Of Players?

Asked by 3 years ago

What I Want

I Want To Make A Timer So If There Isn't Enough Players It Loops The Repeat Loop Again.

Problem

It Subtracts By 2 to 5

Solutions

I've Added If Time Value Is Lower Than 0 Then Do This But That Didn't Work.

Game Script

repeat

        eventTable[2]:FireAllClients(player)
        wait(2)

    until #Player:GetChildren() >= 9

Gui Script

function CountDown(player)

    local Time = this.WaitingGuis.Stat.BG.Seconds

    local BG = this.WaitingGuis.Stat.BG

    repeat

        Time.Value = Time.Value - 1
        BG.Loading.Text = Time.Value
        wait(1)

    until Time.Value == 0
end

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Looping is completely fine and works great HOWEVER there is a better way to do it for better performance. Instead of using

repeat

you can use OnValueChanged like this if your using a value as the number of players. Change

ServerStorage.NumberValue.Changed:Connect()

to wherever the value is located and called.

ServerStorage.NumberValue.Changed:Connect()
if #Player:GetChildren() >= 9 then
-- run your code here
else
0
You can just use loops too epicnmac 63 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
repeat
        eventTable[2]:FireAllClients(player) -- don't need the player variable here (does nothing bc you did fireallclients)
        wait(2)
until #Player:GetChildren() >= 9

-

function CountDown(player) -- player here is also useless as you don't use it (also could just do game.Players.LocalPlayer
    local Time = this.WaitingGuis.Stat.BG.Seconds

    local BG = this.WaitingGuis.Stat.BG

    repeat
        Time.Value = Time.Value - 1
        BG.Loading.Text = Time.Value
        wait(1)
    until Time.Value == 0 -- make it until Time.Value <= 0 so if it goes under 0 before it checks, it will still end
end

Answer this question