Unable to cast string to int64

I am trying to prompt a purchase to the player when they press a purchase buttom in a screengui.

I am getting the erorr Unable to cast string to int64, the ID changes because its stored as a StringValue.

Here is my code

local Player = game.Players.LocalPlayer
local MarketplaceService = game:GetService("MarketplaceService")

script.Parent.MouseButton1Click:Connect(function()
	local ID = tostring(script.Parent.Parent.Parent.Frame.TopValue.Value)
	MarketplaceService:PromptPurchase(Player, ID)
end)

why are you making the ID variable a string, it has to be a number (i think)

could be tonumber

Set the ID to a number before doing so.

local Player = game.Players.LocalPlayer
local MarketplaceService = game:GetService("MarketplaceService")

script.Parent.MouseButton1Click:Connect(function()
	local ID = tostring(script.Parent.Parent.Parent.Frame.TopValue.Value)
	local Number_ID = tonumber(ID)
	if Number_ID then

		MarketplaceService:PromptPurchase(Player, ID)
	else
		print("Failed to turn ID into a number!")
	end

end)

use tonumber() instead of tostring(), it converts a string value to a number value

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.