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

Why is this function returning nil?

Asked by 4 years ago

This is a callable function I'm using to get a user's ID. The issue is, when I call it with a valid username, it returns nil.

function getid(name)
    local s,e = pcall(function()
        local id = game.Players:GetUserIdFromNameAsync(name)
        return id
    end)
    if not s then
        warn(e)
    end
end
1
pcall() runs the function in a separate thread. That thread is not associated with the function that pcall() is running inside of. What you're getting is getid()'s return value, which is nil. You're not getting pcall's return value. DeceptiveCaster 3761 — 4y
0
shut up bashcaster stop stealing my rep nrd >:( Fifkee 2017 — 4y
0
anyways yeah, if you want to get the return value from a pcall, you should instead return "s" instead outside of the pcall. Fifkee 2017 — 4y
0
Since "s" is a boolean, if I return s, it will just return true or false. AlexAuthority 22 — 4y
0
At least it doesn't return nil? DeceptiveCaster 3761 — 4y

Answer this question