I need help fixing this old script

Hello developers! I am currently trying to fix an old game of mine and make it up-to-date. This Script uses the Gamepass service, and what it does is it keeps the gear after you die. Keep in mind, it used to work, I just don’t remember when it stopped working

Broken script:

function HasGamepass(player, passId)
    return game:GetService("MarketplaceService"):PlayerOwnsAsset(player, passId)
end

function Player(p)
	local backpack = p:WaitForChild("Backpack")
	local spawnGear = {}
	local KeepGear = HasGamepass(p, 5649568)
	
	local function Character(char)
		local hmd = char:WaitForChild("Humanoid")
		
		wait(1)
		
		if KeepGear then
			for _,v in pairs (spawnGear) do
				local getGear = game.ServerStorage.Gear:findFirstChild(v)
				if getGear then
					getGear:clone().Parent = p.Backpack
				end
			end
		end
		spawnGear = {}
		
		hmd.Died:Connect(function()
			local gear = {}
			for _,v in pairs (p.Backpack:GetChildren()) do
				if v:IsA("Tool") then
					gear[#gear+1] = v
				end
			end
			for _,v in pairs (char:GetChildren()) do
				if v:IsA("Tool") then
					gear[#gear+1] = v
				end
			end
			for _,v in pairs (gear) do
				v.CanBeDropped = false
				spawnGear[#spawnGear+1] = v.Name
			end
		end)
	end
	
	if p.Character then Character(p.Character) end
	p.CharacterAdded:Connect(Character)
end

for _,v in pairs (game.Players:GetChildren()) do Player(v) end

game.Players.PlayerAdded:Connect(Player)

If you can help, please let me know. Thanks, WE

Try this and let me know, Since roblox no longer supports PlayerOwnAsset for the gamepasses.

function HasGamepass(player, passId)
	return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player, passId)
end

function Player(p)
	local backpack = p:WaitForChild("Backpack")
	local spawnGear = {}
	local KeepGear = HasGamepass(p.UserId, 5649568)

	local function Character(char)
		local hmd = char:WaitForChild("Humanoid")

		wait(1)

		if KeepGear then
			for _,v in pairs (spawnGear) do
				local getGear = game.ServerStorage.Gear:FindFirstChild(v)
				if getGear then
					getGear:clone().Parent = p.Backpack
				end
			end
		end
		spawnGear = {}

		hmd.Died:Connect(function()
			local gear = {}
			for _,v in pairs (p.Backpack:GetChildren()) do
				if v:IsA("Tool") then
					gear[#gear+1] = v
				end
			end
			for _,v in pairs (char:GetChildren()) do
				if v:IsA("Tool") then
					gear[#gear+1] = v
				end
			end
			for _,v in pairs (gear) do
				v.CanBeDropped = false
				spawnGear[#spawnGear+1] = v.Name
			end
		end)
	end

	if p.Character then Character(p.Character) end
	p.CharacterAdded:Connect(Character)
end

for _,v in pairs (game.Players:GetChildren()) do Player(v) end

game.Players.PlayerAdded:Connect(Player)
1 Like

Hmm doesn’t seem to work, and I promise that I do own the gamepass. If you look at it, don’t mind it lol

1 Like

May I know what error you’re getting?

1 Like

O. I fixed it. Nvm. I just had to fix line 2 from yours to
return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player, passId)

1 Like

Oh alright, my bad, I guess did made mistake there haha

1 Like