Is a PCALL neccessary here? (ProfileService)

I’m trying to figure out whether a pcall is neccessary here, I haven’t used them much and i’m trying to figure out where I should put them. It’s the second line where I load the profile.

Thanks.


    local function playerJoined(player)
	
	local profile = profileStore:LoadProfileAsync("Player_"..player.UserId, "ForceLoad") --neccessary?

The key to figure when to use pcall() is when an API is used:

In other words, yes.

1 Like

Also, if you don’t mind me asking, i’m having trouble figuring out how to use pcall on this as well as keep the profile variable for later use?

It would be replacing success with the desired variable.

local yourVariable, response = pcall(function()
    return -- API call here
end)
1 Like

Thanks so much, makes it easy to understand with your help!

pcall() is used exclusively for things that may error - you will need to find official examples using pcall() on a specific piece of code or some documentation stating that you need to use pcall() for that feature. Otherwise you shouldn’t be using pcall. ProfileService guide does not mention anywhere that you need to use pcall().

2 Likes