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

Why does this cause a game script timeout whenever it's activated?

Asked by 4 years ago
Edited 4 years ago

This is reposted btw

function module:Breathing(Player,Bool)
    local Character = Player.Character
    local plrData = game.ReplicatedStorage.PlayerData:FindFirstChild(Player.UserId)
    print(CooldownModule:IsOnCooldown(Player.Character,"Breathing"))
    if Bool and not CooldownModule:IsOnCooldown(Player.Character,"Breathing") and not CooldownModule:IsOnCooldown(Player.Character,"Active") then
        print(Bool)
        local Value = Instance.new("StringValue",Character)
        Value.Name = "Breathing"
        while Character:FindFirstChild("Breathing") and Bool do
            if plrData.Breath.Value < 100 then
            plrData.Breath.Value = plrData.Breath.Value + 1
            wait(0.1)
            end
        end
    elseif not Bool and Character:FindFirstChild("Breathing") then
        CooldownModule:CreateCooldown(Character,"Breathing",0.2)
        for i, v in pairs(Character:GetChildren()) do 
            if v.Name == "Breathing" then
                v:Destroy()
            end
        end
    end
end
0
Which line does it say the timeout was on? LoveingLiamGuy 0 — 4y
0
Also, you don't have to use 0.1. You can leave at as wait() and it will default to the smallest value possible. LoveingLiamGuy 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

The wait function is inside the if statement code block. Here's a summary example:

local a=0
while true do--start loop
    if a==1 then-- since a==0 it skips this if statement
        wait(0.1);-- since the if statement is skipped, this wait function wont run, there's no cool down because while loops run really fast, thereby causing a timeout
    end;
end;

I suggest placing your wait function outside of the if statement, so that regardless of the condition, there will be a cool down to prevent timeout.

Ad

Answer this question