Owned text on your gamepass

I was stating a similarity between the two. What I am saying is that using your current script is not the best idea because it will loop every second when it does not have to. You can run that code once and use PromptPurchaseFinished instead.

No, the problem is that if you did that, it wouldn’t say if the player owned the gamepass when they joined the game again unless you implemented UserOwnsGamePassAsync.

Screenshot 2023-04-10 130642

1 Like

What does the code above that look like?

this:

Make sure you’re ending the script.Parent.MouseButton1Click with an end) and not a end because it has an open parentheses on the “Connect(”

Here is the way I suggested doing it.

local marketplaceService = game:GetService("MarketplaceService")
local passId = 0
local player = game.Players.LocalPlayer
-- The code below checks if a player owns the game pass. If they do, it sets the text to "Owned".
if marketplaceService:UserOwnGamePassAsync(player.UserId, passId) then
    ownedTXT.Text = "Owned"
else
    ownedTXT.Text = "Unowned"
end

-- The code below listens for when a gamepass is purchased. If it is purchased, it sets the text to "Owned".
marketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, pass, purchased)
    if pass == passId and purchased then
        ownedTXT.Text = "Owned"
    end
end)

By the way, you’re using the line

game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer, 38706262)

But you can just shorten that to

MS:PromptGamePassPurchase(plr, 38706262)

You have variables that could be used

2 Likes

like this?:

1 Like

1 Like

As I have suggested above, you can use the PromptGamePassPurchaseFinished event. This will make it so your players do not have to rejoin to get their item. In where I set the text to “Owned”, you could then give them their item there too.

1 Like

No, like this

local MS = game:GetService("MarketplaceService")
local ownedTXT = script.Parent.OWND
local plr = game.Players.LocalPlayer
local GamePassID = 38706262
script.Parent.Activated:Connect(function()
	MS:PromptGamePassPurchase(plr, GamePassID)
end)

while task.wait(1) do
	if MS:UserOwnsGamePassAsync(plr.UserId, GamePassID) then
		ownedTXT.Text = "Owned"
	else
		ownedTXT.Text = "Not Owned"
	end
end
1 Like

Here are some more efficient fixes that I recommend aswell:

  • You can use task.wait() instead of wait()
  • You can use script.Parent.Activated instead of script.Parent.MouseButton1Click
  • You can assign variables like MS to game:GetService("MarketplaceService") because you have a MS variable at the top of your code
  • You can use if MS:UserOwnsGamePassAsync(plr.UserId, GamePassID) then instead of checking if it’s true
1 Like

robloxapp-20230410-1329381.wmv (310.1 KB)

1 Like

and yes it was the speed coil i checked the gamepass before i recorded

1 Like

Does it work? If clicking the button doesn’t work, script.Parent.Activated should be the path to the button that you click, and then .Activated

1 Like

ok so i already owned it like ages ago thats why i have it

1 Like

but when i click the button it says buy but since i already own it its suppose to say owned

1 Like

so yeah thats about it and i wonder if i shouldput a script in the text button

1 Like

Yes, you move the script to the text button.

1 Like