When i reset/die the tools disappear and also when I buy the gamepass i can buy it again so its like not one time purchase
Server Script Service (script)
local MarketplaceService = game:GetService("MarketplaceService")
local gamePassID = 18294052
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true and purchasedPassID == gamePassID then
print(player.Name .. " purchased the game pass with ID " .. gamePassID)
local oofie = game.ReplicatedStorage.ClassicSword:Clone()
oofie.Parent = player.Backpack
end
end
onPromptGamePassPurchaseFinished()
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
And that’s the local script
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamePassID = 18294052
local function promptPurchase()
local player = Players.LocalPlayer
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if hasPass then
--Player got da gamepass
local oofie = game.ReplicatedStorage.ClassicSword:Clone()
oofie.Parent = player.Backpack
else
--Failure purchase
MarketplaceService:PromptGamePassPurchase(player, gamePassID)
end
end```
by this, it appears that you have to click the button to get it again. You don’t have any part of the script that gives it again when you die. Although, something like this could work:
local gamePassID = 18294052
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
wait()
local hasPass = MarketplaceService:UserOwnsGamePassAsync(plr.UserId, gamePassID)
if hasPass then
local oofie = game.ReplicatedStorage.ClassicSword:Clone()
oofie.Parent = plr.Backpack
end
end)
end)
You’re setting the parent of the new item to the player’s backpack, whilst you should be inserting it into his starter gear or both.
local gear = oofie:Clone()
oofie.Parent = player:WaitForChild("StarterGear") --will be given to the player upon spawning
gear.Parent = player.Backpack --also give him it immediately instead of having him reset
You should also implement a script that checks if the player, upon entering the game, owns the gamepass. If he does, it should do what I wrote above so you’d be able to have the tool save between sessions.
Finally, in regards to your last bug, I don’t really have a solution, maybe you’ve made it a dev-product instead of a gamepass or something, but it shouldn’t matter too much.
One issue I have with checking for the PromptGamePassPurchase function on the local side is that tools will work extremely weird, I’d rather just let the server handle all of the sanity checks
You could add this onto your server script as well, rather than just detecting on the client:
local MarketplaceService = game:GetService("MarketplaceService")
local gamePassID = 18294052
game.Players.PlayerAdded:Connect(function(player)
local HasPass = false
local success, message = pcall(function()
HasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if HasPass then
--Player got da gamepass
local oofie = game.ReplicatedStorage.ClassicSword:Clone()
oofie.Parent = player.Backpack
local oofie = game.ReplicatedStorage.ClassicSword:Clone()
oofie.Parent = player.StarterGear
else
--Failure purchase
MarketplaceService:PromptGamePassPurchase(player, gamePassID)
end
end)
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true and purchasedPassID == gamePassID then
print(player.Name .. " purchased the game pass with ID " .. gamePassID)
local oofie = game.ReplicatedStorage.ClassicSword:Clone()
oofie.Parent = player.Backpack
local oofie = game.ReplicatedStorage.ClassicSword:Clone()
oofie.Parent = player.StarterGear
end
end
onPromptGamePassPurchaseFinished()
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true and purchasedPassID == gamePassID then
if player.StarterGear:FindFirstChild("ClassicSword") then
return
end
print(player.Name .. " purchased the game pass with ID " .. gamePassID)
local oofie = game.ReplicatedStorage.ClassicSword:Clone()
oofie.Parent = player.Backpack
local oofie = game.ReplicatedStorage.ClassicSword:Clone()
oofie.Parent = player.StarterGear
end
end
onPromptGamePassPurchaseFinished()
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
I mean like if he already got the tool and tries to buy it again i want it to say You already have this item so when the player leave and come back again i want that player to have the same tool he bought like data store
Shouldn’t the PlayerAdded event already detect if that player has the specific Gamepass ID or not though? It could be possible that your if not success then statement could be returning back as false, which is ending the function early preventing the Player giving the tool when they join the game
game.Players.PlayerAdded:Connect(function(player)
local HasPass = false
local success, message = pcall(function()
HasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
--You don't need this
--if not success then
--warn("Error while checking if player has pass: " .. tostring(message))
--return
--end
if HasPass then
--Player got da gamepass
local oofie = game.ReplicatedStorage.ClassicSword:Clone()
oofie.Parent = player.Backpack
local oofie = game.ReplicatedStorage.ClassicSword:Clone()
oofie.Parent = player.StarterGear
else
--Failure purchase
MarketplaceService:PromptGamePassPurchase(player, gamePassID)
end
end)