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.
What does the code above that look like?
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
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.
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
Here are some more efficient fixes that I recommend aswell:
- You can use
task.wait()
instead ofwait()
- You can use
script.Parent.Activated
instead ofscript.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
and yes it was the speed coil i checked the gamepass before i recorded
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
ok so i already owned it like ages ago thats why i have it
but when i click the button it says buy but since i already own it its suppose to say owned
so yeah thats about it and i wonder if i shouldput a script in the text button
Yes, you move the script to the text button.