Hi everyone, I made a button when you click it it pop up the gamepass, but the problem is when player already own the gamepass, appears an advice “you already own this item. you account has not been charged”, I tried with PromptGamePassPurchaseFinished, but it didn’t work.
Here is the code:
local MPS = game:GetService(‘MarketplaceService’)
local Player = game.Players.LocalPlayer
local RE = game.ReplicatedStorage:WaitForChild(“ChangePlayerCharacter”)
local characterValue = script.Parent:WaitForChild(“CharacterName”)
local istrue = false
local Ttime = 1
local ID = 75665424
MPS:PromptGamePassPurchase(Player,ID)
if MPS:UserOwnsGamePassAsync(Player.UserId, ID) then
script.Parent.MouseButton1Click:Connect(function(player)
if istrue == false then
istrue = true
script.Parent.Check.Visible = true
local charactername = characterValue.Value
RE:FireServer(charactername)
end
end)
RE.OnClientEvent:Connect(function()
wait(Ttime)
istrue = false
local function gamepassPurchaseFinished(...)
print("PromptGamePassPurchaseFinished")
end
MPS.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)
end)
Gamepasses can only be owned one at a time. Since you’re the creator of the gamepass, you already have the gamepass owned, this is why you’re getting the message.
oh no sorry, I don’t know if was not be clear my topic, I will edited again, the main problem is when player own the gamepass, and the player clicks again the skin to equip again, the advice appear
In this line, put the not keyword after the if keyword. Your mistake was checking if the player owns the gamepass before purchasing, which kinda makes it impossible to purchase if the player doesn’t own the gamepass from the start. But the script is supposed to check if the player doesn’t own the gamepass before they can purchase it.
New Script
local MPS = game:GetService('MarketplaceService')
local Player = game.Players.LocalPlayer
local RE = game.ReplicatedStorage:WaitForChild("ChangePlayerCharacter")
local characterValue = script.Parent:WaitForChild("CharacterName")
local istrue = false
local Ttime = 1
local ID = 75665424
script.Parent.MouseButton1Click:Connect(function(player)
if not MPS:UserOwnsGamePassAsync(Player.UserId, ID) then
if istrue == false then
istrue = true
script.Parent.Check.Visible = true
local charactername = characterValue.Value
RE:FireServer(charactername)
end
end
end)
RE.OnClientEvent:Connect(function()
wait(Ttime)
istrue = false
local function gamepassPurchaseFinished(...)
print("PromptGamePassPurchaseFinished")
end
MPS.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)
end)
--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
--//Variables
local LocalPlayer = Players.LocalPlayer
local RE = ReplicatedStorage:WaitForChild("ChangePlayerCharacter")
local characterValue = script.Parent:WaitForChild("CharacterName")
--//Controls
local istrue = false
local Ttime = 1
local ID = 75665424
--//Functions
if not MarketplaceService:UserOwnsGamePassAsync(LocalPlayer.UserId, ID) then
MarketplaceService:PromptGamePassPurchase(LocalPlayer, ID)
end
script.Parent.MouseButton1Click:Connect(function(player)
if not istrue then
istrue = true
script.Parent.Check.Visible = true
local charactername = characterValue.Value
RE:FireServer(charactername)
end
end)
Also next time, please format your code correctly.
Hello? I fixed the code, I needed to load into studio because it’s kinda hard to format here…
local MPS = game:GetService('MarketplaceService')
local Player = game.Players.LocalPlayer
local RE = game.ReplicatedStorage:WaitForChild("ChangePlayerCharacter")
local characterValue = script.Parent:WaitForChild("CharacterName")
local Ttime = 1
local ID = 75665424
script.Parent.MouseButton1Click:Connect(function(player)
if not MPS:UserOwnsGamePassAsync(Player.UserId, ID) then
script.Parent.Check.Visible = true
local charactername = characterValue.Value
RE:FireServer(charactername)
end
end)
RE.OnClientEvent:Connect(function()
wait(Ttime)
istrue = false
local function gamepassPurchaseFinished(...)
print("PromptGamePassPurchaseFinished")
end
MPS.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)
end)
It should work, otherwise it’s an issue with your code.
Do you prompt the purchase on the server? Also I don’t get how in the video it prompts the purchase, even though the code wouldn’t allow that without erroring due to the formatting.
You’ll need to check if the player owns the gamepass first.
local GuiDisabled = UserOwnsGamePassAsync(player, gamepassid)
By default this would be false if the player does not own the gamepass.
in the mousebuttonclicked event you would need to check if GuiDisabled == false
note: make sure to set the value to true when the player does buy the item or else it won’t update.
It does not need to prompted through a serverscript or localscript. It will fire the event either way
He needs to check if the player owns the gamepass and only allow the prompt when the player does not own the gamepass.