Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Unable to cast Instance to int64?

I tried to make my purchasing devproducts a bit cleaner by adding in remote events and shooting the player and product id to the server handler but it returns "Unable to cast Instance to int64".

Heres the handler script:

local mss = game:GetService("MarketplaceService")
local shopevents = game.ReplicatedStorage:WaitForChild("ShopEvents")
local coins = shopevents.Coins100
local coils = shopevents.Coils20


coins.OnServerEvent:Connect(function(player, productId)
	
	mss:PromptProductPurchase(player.UserId, productId)
	
	mss.ProcessReceipt = function(receiptInfo)
		if receiptInfo.ProductId == productId then
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
		
	end
	
end)

Heres the local script:

local Player = game:GetService("Players")
local player = Player.LocalPlayer
local leaderstats = player.leaderstats.Coins
local button = script.Parent
local events = game.ReplicatedStorage:WaitForChild("ShopEvents")
local coins = events.Coins100
local productId = 1333146762

button.MouseButton1Click:Connect(function()
	coins:FireServer(player, productId)
	
	leaderstats.Value = leaderstats.Value  + 100

end)

it returns the error on the server script on line 9. It originally happened because i forgot to put UserId but even when its there its not working. If anyone knows what the issue could be please let me know.

1 answer

✓ Accepted answer

OnServerConnections give you player so dont Send the player again right now productId on the server is player while the other player defined on the server is the default one

OnServerEvent:Connect()

Fixed Localscript

local Player = game:GetService("Players")
local player = Player.LocalPlayer
local leaderstats = player.leaderstats.Coins
local button = script.Parent
local events = game.ReplicatedStorage:WaitForChild("ShopEvents")
local coins = events.Coins100
local productId = 1333146762

button.MouseButton1Click:Connect(function()
    coins:FireServer(productId)

    leaderstats.Value = leaderstats.Value  + 100

end)

This discussion is preserved as it was. New answers, comments, and votes are closed.