Once I click the button, I am prompted to buy the gamepass and the effects are applied, when I click it a second time, it says it once again prompts me to buy it. Why is it not remembering me? I had to turn on third party just to make the prompt show up even though it’s my gamepass.
This script is a local script in the player gui.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remFu = ReplicatedStorage:WaitForChild("Verifier")
local MarketplaceService = game:GetService("MarketplaceService")
local speed = passid
local speebool = false
local player = game.Players.LocalPlayer
script.Parent.Fr.speed.MouseButton1Click:Connect(function()
local ver = remFu:InvokeServer(speed) -- verifies on a server side script
print(ver)
if ver then --gamepass exists
if not speebool then --just button for on off
speebool = true
player.Character.Humanoid.WalkSpeed = 50
else
speebool = false
player.Character.Humanoid.WalkSpeed = 16
end
else
MarketplaceService:PromptGamePassPurchase(player, speed) --no gamepass, prompt purchase
end
end)
Details of server script verifier (remFu)
this is said server script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteFunction = ReplicatedStorage:WaitForChild("Verifier")
local MarketplaceService = game:GetService("MarketplaceService")
local itd
local function verify(player, id)
print("VERIFY WAS CALLED")
itd = id
local hasPass = false
print(hasPass)
-- Check if the player already owns the game pass
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, id)
end)
print(hasPass)
return hasPass
end
remoteFunction.OnServerInvoke = verify
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true and purchasedPassID == itd then
print(player.Name .. " purchased the game pass with ID " .. itd)
-- Assign this player the ability or bonus related to the game pass
player.Character.Humanoid.WalkSpeed = 50
end
end
-- Connect "PromptGamePassPurchaseFinished" events to the "onPromptGamePassPurchaseFinished()" function
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
I think you have to run the Prompt Purchase within a Server Script rather than in a local script. Fire the information in a RemoteEvent and prompt the purchase from the server. So when the button is pressed you need to fire the information over and then in the server script, you need to prompt the purchase. It is only done on the local side in a Local Script in a Player GUI therefore will not save. It will save through a Server Script.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remFu = ReplicatedStorage:WaitForChild("Verifier")
local MarketplaceService = game:GetService("MarketplaceService")
local speed = passid
local speebool = false
local player = game.Players.LocalPlayer
script.Parent.Fr.speed.MouseButton1Click:Connect(function()
local ver = remFu:InvokeServer(speed) -- verifies on a server side script
print(ver)
if ver then --gamepass exists
if not speebool then --just button for on off
speebool = true
player.Character.Humanoid.WalkSpeed = 50
else
speebool = false
player.Character.Humanoid.WalkSpeed = 16
end
else
ReplicatedStorage.EVENTNAME:FireServer(player, speed) --no gamepass, prompt purchase
end
end)
Then after you need to change the server script to prompt it.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteFunction = ReplicatedStorage:WaitForChild("Verifier")
local GamepassID = 'GAMEPASS ID HERE'
local MarketplaceService = game:GetService("MarketplaceService")
local itd
local function verify(player, id)
print("VERIFY WAS CALLED")
itd = id
local hasPass = false
print(hasPass)
-- Check if the player already owns the game pass
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, id)
end)
print(hasPass)
return hasPass
end
remoteFunction.OnServerInvoke = verify
local function PromptPurchase(Player, Speed)
MarketplaceService.PromptGamePassPurchase(Player, GamepassID)
wait(1)
Player.Character.WalkSpeed = 50
end
ReplicatedStorage.EVENTNAME:Connect(PromptPurchase)
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true and purchasedPassID == itd then
print(player.Name .. " purchased the game pass with ID " .. itd)
-- Assign this player the ability or bonus related to the game pass
player.Character.Humanoid.WalkSpeed = 50
end
end
-- Connect "PromptGamePassPurchaseFinished" events to the "onPromptGamePassPurchaseFinished()" function
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
You should check on the server for each player that has joined the server if he owns that gamepass. If he does, award him with sparkles or your prize. You can add a button for equip/unequip that would work accordingly to the players’ data , meaning- you can create a boolean value into the player, whenever he equips it, set it to true. And when unequips-> false.
Now, save that boolean with ds.
When the player joins, check for that data. If that value is true, put that effect on him.
what valkyrop said and ALSO no need to prompt purchase in server side, all it needs is to handle the purchase and set the bools and maybe give speed otherwise if you have saved a bool value of person owning the gamepass you can check with local script and not fire prompt but instead equiping.
Thank you. I have implemented this, however it still makes me buy the gamepass anew and does not save. I think perhaps it is a problem within studio itself.
The issue here is you’re prompting and purchasing in studio, take a look at the following screenshot:
Because this is a test purchase, you’re not actually buying it nor owning the gamepass. Meaning once you prompt this again, it detects you don’t own the Gamepass and prompts it once more.
This won’t occur in actual live games. Test purchases only occur in Studio.