MarketplaceService Bug

Hello Fellow Developers! I am currently in need of support. I am trying to add an “Infinite Lives” Gamepass to one of my games. The problem? Well it doesn’t seem to be working. I am not getting any errors in the output. I have tried many things although none have worked. Before adding the MarketplaceService, it worked fine. Here is my script:

local MarketplaceService = game:GetService("MarketplaceService")
local diedEvent = game.ReplicatedStorage.DiedEvent
local reviveEvent = game.ReplicatedStorage.reviveEvent

local passid = 58747879

local function onPlayerAdded(player)
	if MarketplaceService:UserOwnsGamePassAsync(player.UserId, passid) == true then
		local function loadDiedFunction(player)
			player.Character.Humanoid.Died:connect(function()
				wait(1)
				diedEvent:FireClient(player)
			end)
		end

		game.Players.PlayerAdded:Connect(function(player)
			player:LoadCharacter()
			loadDiedFunction(player)
		end)

		reviveEvent.OnServerEvent:Connect(function(player)
			player:LoadCharacter()
			loadDiedFunction(player)
		end)
	end
end

(This script is not mine)
I appreciate all of the help!

2 Likes

Do you own the gamepass? I believe that might be causing the problem.

I do own the gamepass. I have also tried the script with “passid” set to 0

Did you connect onPlayerAdded to the Players.PlayerAdded event?

When I try that it says “Attempt to index nil with ‘UserId’”

That’s because you put the connection inside of the function… the function IS the connection.

I did that. The problem was that I had an extra set of parentheses in it. This might work.

The script still doesn’t seem to work. No errors in the output either.

No, it won’t. You need to remove the 2nd connection here:

Just remove all of that and I believe this won’t work anyways. I think you need to redo this part.

I haven’t been scripting for too long so I am not sure how to replace it.

I have tried replacing that first line with “local player = game.Players.LocalPlayer”

I believe it is CharacterAdded and not PlayerAdded

That doesn’t seem to work. Any ideas on what else I could try?

Well, I think the script works fine. It’s just the events are a little messed up.

Yeah, that’s because I didn’t make it (Like said in original post)

I just realized that in the output it says “CharacterAdded is not a valid member of Players”

It’s a member of the player that’s added, not the service.

Oh, so like “game.Players.PlayerAdded.CharacterAdded”?
Edit: nvm doesn’t work

The correct way to check for the player’s character is:

game.Players.PlayerAdded:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()
end)

Also, are you running the onPlayerAdded function somewhere? If you defined it, doesn’t mean it actually runs the function

I fixed that earlier. Here is the current version of my script (With the changes you suggested)

local MarketplaceService = game:GetService("MarketplaceService")
local diedEvent = game.ReplicatedStorage.DiedEvent
local reviveEvent = game.ReplicatedStorage.reviveEvent

local passid = 58747879

local Players = game:GetService("Players")

local function onPlayerAdded(player)
	if MarketplaceService:UserOwnsGamePassAsync(player.UserId, passid) == true then
		local function loadDiedFunction(player)
			player.Character.Humanoid.Died:connect(function()
				wait(1)
				diedEvent:FireClient(player)
			end)
		end

		game.Players.PlayerAdded:Connect(function(player)
			local character = player.Character or player.CharacterAdded:Wait()
			player:LoadCharacter()
			loadDiedFunction(player)
		end)

		reviveEvent.OnServerEvent:Connect(function(player)
			player:LoadCharacter()
			loadDiedFunction(player)
		end)
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)

It still doesn’t work