Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Unable to cast Instance to int64?

Asked by 2 years ago

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

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
2 years ago

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)
Ad

Answer this question