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

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

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?

4 comments

0

I don't know why it split the code to every other line

0

Do you own the gamepass?

0

Yes, I do.

0

You should be using: UserOwnsGamePassAsync instead of UserOwnsAsset: https://developer.roblox.com/api-reference/function/MarketplaceService/UserOwnsGamePassAsync

1 answer

✓ Accepted answer
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 :)

7 comments

0

What if the script is a child of a ClickDetector and not a part?

0

then it would be script.Parent.MouseClick

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?

0

Was just making sure @superawesome113 understood :)

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.

0

here fixed uwu.

0

@incapaxx the new code editor is buggy, it does all kinds of things including this

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