Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

regiving a item, after respawn?

Asked by 4 months ago

this is what i got so far, and its working but there is just one problem whenever someone respawn they'll lose the item and are forced to rejoin and I also got 1 major flaw, that it sometimes doesn't run on flooded servers

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local BoomboxID = 9595857

game.Players.PlayerAdded:Connect(function(player)
    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, BoomboxID)
        end)
        if hasPass then
            print("Player has the gamepass")

            local boombox = game.ReplicatedStorage.BoomBox:Clone()
            boombox.Parent = player.Backpack


        end
end)
local function onPromptGamePassPurchaseFinished(player, PurchasedPassID, PurchaseSuccess)
    if PurchaseSuccess == true and PurchasedPassID == BoomboxID then
    print(player.Name .. "Purchased Gamepass")

    local boombox = game.ReplicatedStorage.BoomBox:Clone()
    boombox.Parent = player.Backpack
    end
end


MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)

2 answers

Log in to vote
0
Answered by 4 months ago

I would use Player.CharacterAdded for this. It runs every time a character spawns in. Here is a video of an example.

I rewrote your code:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local BoomboxID = 1087508 -- gamepassId

game.Players.PlayerAdded:Connect(function(player) --runs when a player joins the game
    player.CharacterAdded:Connect(function() -- runs when a character spawns in
    local hasPass
    local success, messsage = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, BoomboxID)
        end)
        if hasPass then
            print(player.Name.." has the gamepass")
            local boombox = game.ReplicatedStorage.BoomBox:Clone()
            boombox.Parent = player.Backpack
        end
    end)
end)
local function onPromptGamePassPurchaseFinished(player, PurchasedPassID, PurchaseSuccess)
    if PurchaseSuccess == true and PurchasedPassID == BoomboxID then
    print(player.Name .. " Purchased Gamepass")

    local boombox = game.ReplicatedStorage.BoomBox:Clone()
    boombox.Parent = player.Backpack
    end
end


MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
0
wow thanks for your fast response! thats exactly what i was looking for!! Ijeremyl 0 — 4mo
Ad
Log in to vote
0
Answered by 4 months ago

thanks for your response thats exactly what i was looking for! thankyou

Answer this question