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

My script keeps giving me an error "Unable to cast value to Object" Can someone help me fix it?

I have a button, right by the VIP door in my game and I want you to be able to buy the gamepass, by pressing the button. Heres my script. The error is it saying "Unable to cast value to Object".

local CLICK_BLOCK = script.Parent
	local ITEM_ID = 5347758
	 
	local Click = Instance.new("ClickDetector")
	Click.Parent = CLICK_BLOCK
	 
	Click.MouseClick:Connect(function(p)
	    game:GetService("MarketplaceService"):PromptGamePassPurchase(p.UserId,ITEM_ID)
	end)

1 comment

0

You're getting this error on what line?

1 answer

✓ Accepted answer

###Invalid Arguement

PromptGamePassPurchase has 2 arguements. The first is a player, which is an Instance. The 2nd is the gamePassId. You are passing the player's userid, not the player.

###Solution

local CLICK_BLOCK = script.Parent
    local ITEM_ID = 5347758

    local Click = Instance.new("ClickDetector")
    Click.Parent = CLICK_BLOCK

    Click.MouseClick:Connect(function(p)
        game:GetService("MarketplaceService"):PromptGamePassPurchase(p,ITEM_ID)
    end)

1 comment

0

Thank you so much! It works!

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