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

I'm asking to see if the player owns a gamepass, answer comes back false. Help?

Asked by 5 years ago

So I have a script where it checks to see if the user owns a gamepass, if they do it prints their name, If they don't it prints "user name doesn't own gamepass".

 local id = 5179136

script.Parent.MouseClick:Connect(function(player)

game.MarketplaceService:PromptGamePassPurchase(player, id)

if game:GetService("MarketplaceService"):UserOwnsAsset(player, id) == true

then print(player.Name)

end

if game:GetService("MarketplaceService"):UserOwnsAsset(player, id) == false

then print(player.Name.." Does not own this gamepass.")

end

end)

What did I do wrong?

0
I don't know why it split the code to every other line superawesome113 112 — 5y
0
Do you own the gamepass? DeceptiveCaster 3761 — 5y
0
Yes, I do. superawesome113 112 — 5y
0
You should be using: UserOwnsGamePassAsync instead of UserOwnsAsset: https://developer.roblox.com/api-reference/function/MarketplaceService/UserOwnsGamePassAsync Alexander_Ashford 231 — 5y

1 answer

Log in to vote
0
Answered by
Creacoz 210 Moderation Voter
5 years ago
Edited 5 years ago
local id = 5179136



script.Parent.ClickDetector.MouseClick:Connect(function(player)

game.MarketplaceService:PromptGamePassPurchase(player, id)

if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then

print(player.Name)

else

print(player.Name.." Does not own this gamepass.")

end

end)

So first at the start you did script.Parent.Mouseclick and forgot the Clickdetector xd

Second of all UserOwnsGamePassAsync needs the player id and not only the player. So Instead of doing (player, id), its (player.UserId, id). I also made it a little simplier :)

0
What if the script is a child of a ClickDetector and not a part? DeceptiveCaster 3761 — 5y
0
then it would be script.Parent.MouseClick Creacoz 210 — 5y
0
Messy code, you are meant to be the teacher, you should be teaching good practices, the code is already not indented in the OP, why incentivise that behaviour? User#24403 69 — 5y
0
Was just making sure @superawesome113 understood :) Creacoz 210 — 5y
View all comments (3 more)
0
I do have the code indented in my script, it just didn't get indented when I copied it over into the code bracket. superawesome113 112 — 5y
0
here fixed uwu. Creacoz 210 — 5y
0
@incapaxx the new code editor is buggy, it does all kinds of things including this SteamG00B 1633 — 5y
Ad

Answer this question