Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

regiving a item, after respawn?

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

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)

1 comment

0

wow thanks for your fast response! thats exactly what i was looking for!!

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

This discussion is preserved as it was. New answers, comments, and votes are closed.