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

Loop won't break when telling it to break through an BindableFunction?

Asked by 4 years ago

I am currently working on a King of The Hill script and the loop doesn't seem to be breaking at all.

So, basically, I am firing a BindableFunction which is script.Parent.King. That is my BindableFunction, however, when I execute it when I am out of range, the loop doesn't break.

local val = false

local function update(upd)
    val = upd
    while wait(1) do
        if val == false then
            val = false
            break
        end
        print("give | king of hill")
    end
end

script.Parent.King.OnInvoke = update

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:connect(function(character)
        while wait(0.5) do
            local mag = (script.Parent.Position - character:FindFirstChild("HumanoidRootPart").Position).magnitude
            if mag <= 16 then
                script.Parent.King:Invoke(true)
            else
                script.Parent.King:Invoke(false)
            end
        end
    end)
end)

That is my code, please let me know if you have any solutions.

Answer this question