Unable to cast value to Object

I’m getting the error “Unable to cast value to Object” when this script is ran:

local debounce = false
local cooldownTime = 1
local MPS = game:GetService("MarketplaceService")
local productID = 1131007865
script.Parent.Triggered:Connect(function(player)
	if debounce == false then
		MPS:PromptProductPurchase(player, productID)
		MPS.PromptProductPurchaseFinished:Connect(function (player, productID, isPurchased)
			if isPurchased then
				game.ReplicatedStorage.RemoteEvents.Tip:FireClient(player)
			end
			debounce = true
			wait(cooldownTime)
			debounce = false
		end)
	end
end)

Note: This script is inside of a ProximityPrompt

you need to change
MPS.PromptProductPurchaseFinished:Connect(function (player, productID, isPurchased)

to

MPS.PromptProductPurchaseFinished:Connect(function (player.UserId, productID, isPurchased)

because players user id is a value , and the player is an object. i hope this heplful!!!

I changed it to that and now it doesn’t prompt the product purchase.

dont change the prompt. it needs to get player, but ProductFinished needs to get UserId of the player

Which line are you getting this error on?

That’s all I changed.‎‎
‎‎‎‏‏‎ ‎‏‏‎ ‎

can u tell the thing that Jayblox said?
Which line are you getting this error on?

I’m not getting an error anymore but it’s not prompting the purchase anymore.
code:

local debounce = false
local cooldownTime = 1
local MPS = game:GetService("MarketplaceService")
local productID = 1131007865
script.Parent.Triggered:Connect(function(player)
	if debounce == false then
		MPS:PromptProductPurchase(player, productID)
		MPS.PromptProductPurchaseFinished:Connect(function (player.UserId, productID, isPurchased)
			if isPurchased then
				game.ReplicatedStorage.RemoteEvents.Tip:FireClient(player)
			end
			debounce = true
			wait(cooldownTime)
			debounce = false
		end)
	end
end)

change the code back and test it again

1 Like

I’m getting the error “Unable to cast value to object on” line 10.
Edit its line 10.

if the error was on line 10 then there is an error when youre firing the client


Got it from devhub

yes i thought it was the error but error was on the line 10 , thanks for telling

So what do I need to change to make it work?

script should work right , i didnt understand :confused:

1 Like

can u try to change FireClient to
:FireClient(game.Players:GetPlayerByUserId(tonumber(player)))

this should work

1 Like

It works.
Btw when if I use player.UserId isPurchased gets a blue line under it on line 9.
So do I need to add .UserId back or not?

1 Like

dont use player.UserId i told you wrong

1 Like

and if it is works , really good!!! :slightly_smiling_face:

1 Like

Thanks for the help!
‎‎‎‏‏‎ ‎‏‏‎ ‎‎‎‎‏‏‎ ‎‏‏‎ ‎‎‎‎‏‏‎ ‎‏‏‎ ‎‎‎‎‏‏‎ ‎‏‏‎ ‎‎‎‎‏‏‎ ‎‏‏‎ ‎‎‎‎‏‏‎ ‎‏‏‎ ‎‎‎‎‏‏‎ ‎‏‏‎ ‎‎‎‎‏‏‎ ‎‏‏‎ ‎