InternalServerError help

Recently I have been getting an error popping up that looks like this

InternalServerError
 ReplicatedStorage.Modules.Library, line 150 - function getPlayerClickIncrement
ServerScriptService.Main Script, line 194

 Server Version: 0.5.2

I went ahead and investigated as this was a new thing appearing and it seems to have something to do with :UserOwnsGamePassAsync in the module script. Here is the function in the ModuleScript

function lib.getPlayerClickIncrement(currentPlayer, playersHammer, playerBonus)
	local hammerTool = lib.getHammer(playersHammer) 
	local hammersClickIncValue = hammerTool:FindFirstChild("Value").Value
	
	local currentClickIncrement = hammersClickIncValue
	local playerCurrentRebirths = lib.getPlrStat(currentPlayer, "PlayerRebirth")

	if playerCurrentRebirths.Value > 0 then --Get Rebirth Bonus
		currentClickIncrement = currentClickIncrement + playerCurrentRebirths.Value
	end
	
	if playerBonus then --Get Player Buff Bonus
		currentClickIncrement = currentClickIncrement * 2
	end
	
	local playerHasDoubleXpGamepass = MarketService:UserOwnsGamePassAsync(currentPlayer.UserId, 6838377) --Get Gamepass Bonus THIS IS LINE 150
	if playerHasDoubleXpGamepass == true then
		currentClickIncrement = currentClickIncrement * 2
	end

	return currentClickIncrement
end

This function is being called every time the Player clicks to get how many points that Player should receive when they click. My initial theory was I am asking if the Player owns the gamepass too much. So I was going to make a table of all the Player’s who own the gamepass and just check if the user who clicked Is in that table instead of constantly firing UserOwnsGamePassAsync. But It states on the wiki page that

Results of this function are remembered so that repeated calls will return quicker. This function will always return true if the player owns the game pass upon first entering a server after having purchased the game pass.

So I don’t think calling it firing every time they click should be a problem. Is there anything else this could be? Could something else on the server be affecting this?

In some cases a module can hide errors. I would put the function in the script to get a better idea of the error. Remember this is still an API call so to be safer I would wrap it in a pcall.

Even though UserOwnsGamePassAsync should be cached it still needs to “check” on the Roblox side of things. I would use a variable and upate this variable if they buy the game pass ingame.

2 Likes

So you think it would be better to just create a table of Player’s who own the gamepass? I went ahead and did that. Now, whenever a Player joins I check if they own the gamepass and if they do insert them into the table. I also insert them into the table if they purchase the gamepass in-game. UserOwnsGamePassAsync should only be getting called when they first enter the game now. Hopefully, that fixes this.

1 Like

Also remember to remove the data when the leave the game XD

1 Like