Roblox error or code error?

Recently, there was an error in the console that said internal error or something. It said that these lines of codes were the ones that were causing the error. The error also caused part of my game to stopped working so I could not ignore this. This function would be ran when a player’s character is loaded. The error seemed to appear when a lot of people are in the server. Is there something wrong with my code?

function Gamepasstest(player,id)
	if marketplace:UserOwnsGamePassAsync(player.UserId,id) == true or player.UserId == 2274979528 then
		return true
	else
		return false
	end
end
1 Like

Basically I would say if Gamepasstest([player name],[gamepass] == true then I would give the player the benefits they needed. I ran this line about like 10 times or something when the player character loads for different groups.

Here’s an example of the error I was talking about


Also this
image

You should use this instead.

local function ownsgamepass(userid,gamepassid)
	local s,res = pcall(marketPlaceService.UserOwnsGamePassAsync,marketPlaceService,userid,gamepassid)
	if not s then
		res = false
	end
	return res
end
1 Like

Little tip, you can eliminate the if-statement entirely because of how logical operators work in Lua:

local successful, result = pcall(...)
return successful and result

If not successful, it will return false because both statements aren’t truthy, if it is successful, it will return the result.

1 Like

I’m going to mark this as the solution for now as the problem is not occurring since not a lot of players are playing the game now. I will find a new solution when the error reproduces.