Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Not returning the set boolean?

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

1 comment

0

Thank you @radusavin366 for having the solution to this! Never knew it was something so simple...

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.