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

Not returning the set boolean?

Asked by 6 years ago
Edited 6 years ago

As I was working on a module script, I found that when I tried calling a "return true" or "return false", it'd either "return nothing" or "return nil". I tried to figure out why it was doing this, but was unable to come to a conclusion.

function api.isPlayer(name)
    local s, m = pcall(function()
        local plr = Players:FindFirstChild(name)
        if plr then
            return true
        else
            return false
        end
    end)
    if s then return else error(m) end
end
0
Thank you @radusavin366 for having the solution to this! Never knew it was something so simple... Nurame_Duff 7 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

If you're expecting the api.isPlayer function to return either of those, it won't because you're not returning anything if the pcall succeeds. you should modify if s then return ... to if else then return m.

Ad

Answer this question