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

[answered]unable to cast instance to int64?

I set up a remote event to handle purchases for my game because it makes me feel neater and I'm getting "unable to cast instance to int64" in the dev console the script causing this error is: and the error occurs on line 7 and line 23

local MPService = game:GetService("MarketplaceService")
local HttpService = game:GetService("HttpService")
local Webhook = "empty because one of the reasons im using a remote event is security"
local event = game.ReplicatedStorage.hey

event.OnServerEvent:Connect(function(player, assetId)
	promptpurchase(player, assetId)
end)

function GetSales(assetId)
	local data = HttpService:JSONDecode(HttpService:GetAsync("https://api.roblox.com/Marketplace/ProductInfo?assetId="..assetId))
	local sales = data.Sales
	return(sales)
end

function GetName(assetId)
	local data = HttpService:JSONDecode(HttpService:GetAsync("https://api.roblox.com/Marketplace/ProductInfo?assetId="..assetId))
	local name = data.Name
	return(name)
end

function promptpurchase(player, assetId)
	MPService:PromptPurchase(player, assetId)
	MPService.PromptPurchaseFinished:connect(function(Player, assetID, isPurchased)
		if isPurchased then
			local HookData = {
			['username'] = "shop",
			['content'] = "Player: "..player.Name.."\nAsset Bought: "..assetId"
			}
			HookData = HttpService:JSONEncode(HookData)
			HttpService:PostAsync(Webhook, HookData)
		end
	end)
end

I've literally tried every possible thing I could think of, but lua's a very confusing language to me sometimes with the errors I get.

anyone got any ideas?

edit: some of you asked for what i was inputting as params so here it is:

game.ReplicatedStorage.hey:FireServer(game.Players.LocalPlayer, 320412452)

4 comments

0

It's telling you which line is erroring?

2

It means that you've set a property to an instance when the property is an integer. I suggest reviewing your code and the values you're writing to your instances' properties. It would also help if you posted the line the error occurs on.

0

the error occurs on line 7 and line 23

0

It means that assetId is an Instance then, your event is maybe sending an IntValue or something rather than IntValue.Value? Either way at least you know the problem

1 answer

Your error literally means that you are trying to store an object (like a "player" or "part" or "model") into a number storage container (basically like doing "part" + 1 which doesn't make sense). Sorry if that didn't make sense because I don't know how to word it right but I hope I can at least give you an idea with the "part" + 1 thing.

My best guess is that when you are passing in the gamepass's ID through the event, you are actually giving it the object itself rather than a number (which is the gamepass's ID). Would be more useful if you can show us your other script that calls the event to trigger this.

Just make sure to check if you are not sending anything else than a number for the second parameter when you prompt the purchase (the gamepass ID).

If you have any questions or issues, please contact me (as this may not be the solution). ;)

6 comments

0

I would use the term Instance instead of object, especially since that is quite literally the term the error says after all

0

game.ReplicatedStorage.hey:FireServer(game.Players.LocalPlayer, 241230142)

0

There's your issue, the player who Fires events is already the first argument so in reality your server script is receiving arguments (player, player, id)...all you need to do is remove the game.Players.LocalPlayer argument

0

thanks, that worked

0

No problem

0

BTW, accept this as the answer. People tend to come here if it's not solved.

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