#function doesn't return

24 messages · Page 1 of 1 (latest)

compact coral
#

function doesn't return despite there being a return confined in an if statement

local function thething(button, gate, duration, db)
    if db then 
        duration.Value = 10 
        return 
    end
    
    button.Transparency = TP + 0.5
    gate.Transparency = TP + 0.8
    gate.CanCollide = not CC

    while duration.Value > 0 do
        task.wait(1)
        duration.Value -= 1
        print(duration.Value)
    end

    reset(button, gate, duration)
    duration.Value = 10
end

the rest of the code:

for _, button in pairs(buttons:GetChildren()) do
    local db = false
    local db2 = true
    local duration = button:FindFirstChild("duration")
    
    button.Touched:Connect(function(hit)
        if not hit.Parent:FindFirstChild("Humanoid") then return end
        
        for _, gate in pairs(gates:GetChildren()) do
            if button:FindFirstChild("ref").Value == gate:FindFirstChild("ref").Value then
                
                if duration.Value <= 8 and not db then
                    db = true
                    print("resetting")
                    reset(button, gate)
                    task.wait(1)
                    db = false
                    db2 = true
                end
                
                if duration.Value ~= 10 and duration.Value > 8 then
                    print("returning")
                    return
                end
                
                if duration.Value == 10 then
                    if db2 then
                        db2 = false
                        print("proceeding")
                        thething(button, gate, duration, db)
                    end
                end
            end
        end
    end)
end
marsh dust
#

Does it print proceeding

compact coral
marsh dust
vague fjord
#

return you mean, doesn't end the function there?

dense zodiac
#

are you trying to end the whole function from inside an if statement?

vague fjord
#

im just confused because he has 1 nil return and is confused why he's "not returning anything"

dense zodiac
#

maybe he thinks it’s gonna print something lol

compact coral
dense zodiac
#

might need to rewrite your with else statements for it completely stop

compact coral
#

one if statement inside the loop to break then another after it breaks to return

dense zodiac
compact coral
#

if i do return inside the if statement of the while loop it won't stop

#

if i say break it will stop the loop and won't return

#

i've implemented break into the while loop yet it still doesn't work

dense zodiac
#

lemme write a block rq

#
local function thething(button, gate, duration, db)
    if db then 
        duration.Value = 10 
    else
      -- whatever you want to happen when "duration.Value ~= 10"
    end
end
#

when you return you would just end the statement that it is inside

#

and not end any parent statement if you will

compact coral