Unable to cast Instance to int64 with :GetProductInfo()

I made a system where you can enter the ID of an item and it returns information about it. However, I keep on getting this error:
Unable to cast Instance to int64

Can someone check my code to see my error? Thanks!

Client:

Submit.MouseButton1Click:Connect(function()
	local number = tonumber(EnterId.Text)
	if number then
		getProductInfoEvent:FireServer(Player,number)
	else
		print('not valid ID')
	end
end)

Server:

getProductInfoEvent.OnServerEvent:Connect(function(number,Player)
	local enteredAsset = MarketplaceService:GetProductInfo(number) -- error line

The first argument of OnServerEvent is always the player who fired the event. When you say :FireServer(Player,number) the server is getting the arguments player, player, number but you’re writing it as number, player meaning when you say GetProductInfo(number) you’re passing the player as the argument. You can fix this by replacing your code as follows.

Client:

Submit.MouseButton1Click:Connect(function()
	local number = tonumber(EnterId.Text)
	if number then
		getProductInfoEvent:FireServer(number)
	else
		print('not valid ID')
	end
end)

Server:

getProductInfoEvent.OnServerEvent:Connect(function(Player, number)
	local enteredAsset = MarketplaceService:GetProductInfo(number)

You can read more about the behaviour of RemoteEvents here:

1 Like

That makes sense, I forgot Player was the first parameter. Thanks!

1 Like