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

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

Asked by 5 years ago

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)

0
You're getting this error on what line? Leamir 3138 — 5y

1 answer

Log in to vote
1
Answered by
green271 635 Moderation Voter
5 years ago

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)

0
Thank you so much! It works! protectiverobos -50 — 5y
Ad

Answer this question