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

[SOLVED] "Unable to cast instance to int64" fix?

Asked by 5 years ago
Edited 5 years ago

This question has been solved by the original poster.

I'm making a gamepass that allows a player to sell ores from anywhere when the player clicks a button in a GUI. Since TextButtons usually use LocalScripts, I have to use remote events to affect the players money across the whole server. However, I've come across an issue. The error states "Unable to cast instance to int64", here's the script:

01local btn = script.Parent
02local db = true
03local plr = game.Players.LocalPlayer
04local id = 7596478
05local service = game:GetService("MarketplaceService")
06local event = game.ReplicatedStorage.Events.SellOres
07 
08btn.MouseButton1Down:Connect(function()
09    if db == true then
10        db = false
11        if service:UserOwnsGamePassAsync(plr, id) then --this should change from (plr, id) to (plr.UserId, id)
12            local amount = plr.leaderstats["Ore Value"].Value
13            event:FireServer(amount)
14        else
15            service:PromptGamePassPurchase(plr, id)
16        end
17        wait(0.1)
18        db = true
19    end
20end)

I know that the error means that what I'm doing is sort of like doing "part + 1", which doesn't make sense. But I don't know what I've done wrong in the script. Please help me if you know the answer, thanks!

Edit: Literally right after I post this I go back to the studio and then remember that I have another script that makes the same statement, so I open that up and realize that I have to use the player's UserId, not the player himself. Whoops!

Answer this question