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

Unable to cast value to object while using marketplaceservice?

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?

1 comment

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

1 answer

✓ Accepted answer

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.

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