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

Unable to cast value to object while using marketplaceservice?

Asked by 4 years ago
Edited 4 years ago
game.ReplicatedStorage.GetDriver.OnServerEvent:Connect(function(player)
    local mps = game:GetService('MarketplaceService')
    mps:PromptGamePassPurchase(player.UserId, 7085552)
    if mps:PromptGamePassPurchaseFinished(player.UserId, 7085552) or                    mps:UserOwnsGamePassAsync(player.UserId, 7085552) then
        player.PlayerGui.CarGui.Frame.Visible = false
        game.ReplicatedStorage["Police Car"]:Clone().Parent = workspace
    else

    end
end)
--Script in ServerScriptService

This is my script above. If some guy clicks a button, then it will use a RemoteEvent to make purchases(THIS IS A SERVER SCRIPT!!!) but in line 3 (mps:PromptGamePassPurchase(player.UserId, 7085552) we get Unable to cast value to object I checked if the sent info was right yes the userid was my user id(i'm the tester!) and the gamepass id is right but can anybody fix this error?

0
oops i forgot i had to use connect function on line 4 but anyways no matter cause the line is on line 3 lol tree_tree00 48 — 4y

1 answer

Log in to vote
3
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

The API reference here tells you what you need to put inside the parameters for PromptGamePassPurchase. It says that the first parameter is the player instance, and the second is the gamepass id.

You have the gamepass id bit correct, but you need to pass the player, not the player's userId. To do that, delete '.UserId' from line 3 and you are passing in the player.

Ad

Answer this question