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

How would I break a loop based on a bool value changing?

Asked by 3 years ago
Edited 3 years ago

So i want to make a round system, like a deathmatch. The round is 10 minutes Long but if a player gets 30 kills then i want a bool value to be set to true. Therefore i want the round system to break once the bool value sets to true. How can i do this? Please help.

3 answers

Log in to vote
0
Answered by
cancle5 120
3 years ago

I would use a changed

kills.Value.Changed:Connect(function()
    -- You can check how many kills they have and if they have a certain number it ends the              
    game
    if kills.Value == 30 then
        -- end the game
    end
end)

I don't recommend using a while true do/ while wait() do or a repeat until since it checks a ton of times instead of just doing smthing when the value changes it makes the game lag a little.

0
how would that break a loop though? ScentedTrashCan 16 — 3y
Ad
Log in to vote
0
Answered by
valk_3D 140
3 years ago
Edited 3 years ago

if its a variable in a scrip do:

while wait(0.1) do
    if Bool ~= true then
        --Code
    else
        break --ends the loop
    end
end

if its a value do:

Bool:GetPropertyChangeSignal("Value"):Connect(function()
    if Bool.Value ~= true then
        --Code
    else
        return
    end
end)
0
Well the main manager is a function, and inside the function is the loop. It is a bool value located in replicated storage. So do I connect the script inside the loop or what do i do? ScentedTrashCan 16 — 3y
0
I am kind of new to coding i am sorry ScentedTrashCan 16 — 3y
Log in to vote
0
Answered by 3 years ago

Thats exactly what repeat until loops are for.

repeat
      -- round logic
until (statement)

Answer this question