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)
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)