Unable to cast value to Object

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Make my rank management center work properly
  2. What is the issue? Include screenshots / videos if possible!
 20:21:56.987 - Unable to cast value to Object
20:21:56.989 - Stack Begin
20:21:56.989 - Script 'Players.49dec.PlayerGui.RankManagement.Main.ScrollingFrame.Example Rank.TextButton.LocalScript', Line 7
20:21:56.989 - Stack End
Script:
script.Parent.MouseButton1Click:Connect(function()
    local plr = game.Players.LocalPlayer
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players.LocalPlayer.UserId, 5694417) then
    local rankid = 4 --This is the rank that the user will be promoted/demoted to.
       game.ReplicatedStorage.RankPlayer:FireServer(game.Players.LocalPlayer, rankid)
else
        game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer.UserId, 5694417)
    end
end)
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I went on discord, and a experienced scripter told me to fix so it’s userid, gpid instead of gpid,userid.

2 Likes

which line is giving the error?

The method shown, PromptGamePassPurchase, uses a Player instance, not a player ID. Just remove the .UserId and it’ll work.

2 Likes

It said that it was on “Line 7”

Okay, thanks. I’ll try and see if it does.

I believe that in the PromptGamePassPurchase function, the first parameter should be a Player object, not a UserId.

1 Like

yeah but the lines arent numbered, i dont know if you have anything else in that script

Uhhhh, I took a tutorial for the rank management center…

And I took the ui template.

I then fixed the script up a bit so that it’s not gpid, userid

PromptGamePassPurchase does require the Player, not the Player’s UserId


https://gyazo.com/61cde6dabe2a3ab669e685c609a4abe2

The gamepass is not $50 robux


https://gyazo.com/61cde6dabe2a3ab669e685c609a4abe2

This is what I received on removing UserId, however it’s not my gamepass…

make sure you have the correct Id

Oh, I got it. Thank you very much for the help.