Why Does My GamePass Item Disappear After The Player Dies?

I have a gamepass Item in my game the script I have that gives the item works fine but when the player who owns the pass dies the tool gets removed from their inventory here is the script:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local boombox = game.ReplicatedStorage.Tools:WaitForChild('Boombox'):Clone()


local gamePassID = 45333610 

local function onPlayerAdded(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 == true then
		print(player.Name .. " owns the game pass with ID " .. gamePassID)
		boombox.Parent = player.Backpack
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)

Thanks.

1 Like

This is because you only check when the player is added, you should also check when the character is added.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local boombox = game.ReplicatedStorage.Tools:WaitForChild('Boombox'):Clone()


local gamePassID = 45333610 
        local function onPlayerAdded(player)
	local function CheckForPass()
        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 == true then
		print(player.Name .. " owns the game pass with ID " .. gamePassID)
		boombox.Parent = player.Backpack
	end
end
  player.CharacterAdded:Connect(function(char)
            CheckForPass()
        end)
end

Players.PlayerAdded:Connect(onPlayerAdded)
2 Likes

Add a CharacterAdded event, or copy that tool into his StarterGear.

1 Like

I got an error saying:

attempt to index nil with 'CharacterAdded'

sorry i was kind of in a rush, let me do the coed in studio.

1 Like

Should work fine!:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local boombox = game.ReplicatedStorage.Tools:WaitForChild('Boombox'):Clone()
local gamePassID = 45333610 

Players.PlayerAdded:Connect(function(player)
	local function CheckForPass()
		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 == true then
			print(player.Name .. " owns the game pass with ID " .. gamePassID)
			boombox.Parent = player.Backpack
		end
	end
	
	player.CharacterAdded:Connect(function(char)
		CheckForPass()
	end)
	
end)

Note: Make sure you always use RBXScriptSignals with non local functions attached: Player.PlayerAdded:Connect(function(...))

1 Like

Hmm wierd Iā€™m getting an error thats saying:

The Parent property of Boombox is locked, current parent: NULL, new parent Backpack

Im not experiencing any errors, send me a screenshot of your explorer with the tools folder selected.

1 Like


Here
Its Not In My inventory Because I reset my player

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local boombox = game.ReplicatedStorage.Tools:WaitForChild('Boombox'):Clone()


local gamePassID = 45333610 

local function onPlayerAdded(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 == true then
		print(player.Name .. " owns the game pass with ID " .. gamePassID)
		boombox.Parent = player.StarterGear
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)
4 Likes