-
What do you want to achieve? I’m attempting to make a gamepass system, where when you buy a gamepass, you get an item, and when you rejoin, you get the item.
-
What is the issue? The rejoin part is working, but the part in the code where it checks if the user purchased isn’t working and is only registering IsPurchesed as false, even if a user clicks buy.
-
What solutions have you tried so far? Searching development hub, going through the API documentation.
Code:
local id = 12345
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local passname = "Hitbox" --Set this to whatever the gamepass name
local ui = game.StarterGui
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, id) then
print("User owns pass")
for i, v in pairs(script.ToolFolder:GetChildren()) do
local clone = v:Clone()
clone.Parent = player.Backpack
end
else
end
end)
end)
game.Workspace.WorkspaceParts.TouchPart.Touched:Connect(function(touched)
local player = game:GetService("Players"):GetPlayerFromCharacter(touched.Parent)
if player then
print("Part touched!")
game:GetService("MarketplaceService"):PromptGamePassPurchase(player, id)
print("Prompt fired!")
end
end)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, isPurchased)
if isPurchased == true then
print(player.Name.."Owns product!")
for i, v in pairs(script.ToolFolder:GetChildren()) do
local clone = v:Clone()
clone.Parent = player.Backpack
end
ui.gamepassGui.TextLabel.Text = player.Name.. "bought the" ..passname.. "gamepass!"
ui.gamepassGui.TextLabel.Visible = true
wait(5)
ui.gamepassGui.TextLabel.Visible = false
else
print(player.Name .. " didn't buy an item")
end
end)