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?
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.