Infinite Live Gamepass Problem

So I want to make an infinite live gamepass for a story game, but I have a problem. I want to make if they have this gamepass, they will respawn, but if they dont they will get the ui to go back to lobby or respawn with a dev product. This is my script:

local TweenService = game:GetService("TweenService")
local MarketplaceService = game:GetService("MarketplaceService")
local TeleportService = game:GetService("TeleportService")
local player = game.Players.LocalPlayer


local diedEvent = game.ReplicatedStorage.Remotes.DiedEvent
local reviveEvent = game.ReplicatedStorage.Remotes.reviveEvent
local boughtLifeEvent = game.ReplicatedStorage.Remotes.boughtLifeEvent

local MarketplaceService = game:GetService("MarketplaceService") --> Get the service where gamepasses are stored.
local Players = game:GetService("Players") --> Get the service of players.
local gamepassid = 38763632 --> Replace the 000000 with your gamepass.

--> Script


local ScreenGui = player.PlayerGui.MainGui
local extra_life = false

local function teleportToLobby()
	TeleportService:Teleport(8832292226) -- change to lobby ID
end
game.Players.PlayerAdded:connect(function(plr) --> When player added then function
	plr.CharacterAdded:connect(function(char) --> When character added then function
		repeat wait() until char.Humanoid
		char.Humanoid.Died:connect(function() --> When the user dies.
			if MarketplaceService:UserOwnsGamePassAsync(plr.UserId, gamepassid) then --> If the user owns the gamepass then
				plr:LoadCharacter() --> Load the character back into the game instantly.
				extra_life = true
			end
		end)
	end)
end)

local function startTimer()
	local timer = 15
	repeat
		timer = timer - 1
		ScreenGui.Died.timer.Text = timer
		wait(1)
	until timer <= 0 or extra_life == true
	if extra_life == true then
		reviveEvent:FireServer()
		ScreenGui.Died.Visible = false
	else
		teleportToLobby()	
	end
end

boughtLifeEvent.OnClientEvent:Connect(function()
	extra_life = true
end)

ScreenGui.Died.continue.MouseButton1Down:connect(function()
	MarketplaceService:PromptProductPurchase(player, 1255419788)-- change to product ID
end)

ScreenGui.Died.btl.MouseButton1Down:connect(function()
	teleportToLobby()
end)

diedEvent.OnClientEvent:Connect(function()
	ScreenGui.Died.Visible = true
	startTimer()
end)

Thanks, hope someone know the answer!

3 Likes

Anyone know the answer? I still dont get the answer!

On mobile right now so typing is weird. What is the problem?

Even tho I have the inf pass, it didnt respawn me!

Its in the ServerScriptService Btw!

can u show what error comes up cuz than it would be easier to see whats wrong

You can’t fire server in a server script “revive event”
So i suggest using a bindeable event instead

No Error, just nothing, its just not working!

The entire script is a bit of a mess.
You have this one script handling some of the server-side code despite being in a local script.

To fix this, you should handle the respawning on the server for it to be reflected to every player. You should re-evaluate this setup.

Can u show me the example on how to do that?

1 Like

Rather than checking when the player dies in this script, do it in a script ran on the server. Have it automatically respawn the player if he owns the gamepass, otherwise fire a remote event to view the death screen.

If you are unsure on how some of these components work, check out this article:

Ensure you have adequate understanding of the client-server model before tackling this problem.

1 Like

Ah okay, let me try that. Is it okay if I ask you something that I dont understand while doing it?

You can certainly ask for help, but we aren’t really lowed to provide full scripts on the devforum.

1 Like

Yea sure, I tried you suggestion, its working, the player respawn but the UI didnt go away from my screen, but when I see it with shift+p my character is alive

Done it, I use a very work around solution, so that it will make the ui invisible everytime u ded. Thanks for the help everyone!

Its working in studio but not in roblox :skull:
This is my code:

local MarketplaceService = game:GetService("MarketplaceService") --> Get the service where gamepasses are stored.
local Players = game:GetService("Players") --> Get the service of players.
local gamepassid = 38763632 --> Replace the 000000 with your gamepass.
local boughtLifeEvent = game.ReplicatedStorage.Remotes.boughtLifeEvent
local Checkifowngamepass = game.ReplicatedStorage.Remotes.CheckIfOwnGamepass
game.Players.PlayerAdded:connect(function(plr) --> When player added then function
	plr.CharacterAdded:connect(function(char) --> When character added then function
		repeat wait() until char.Humanoid
		char.Humanoid.Died:connect(function() --> When the user dies.
			if MarketplaceService:UserOwnsGamePassAsync(plr.UserId, gamepassid) then --> If the user owns the gamepass then
				plr:LoadCharacter() --> Load the character back into the game instantly.
				Checkifowngamepass:FireClient(plr)
			end
		end)
	end)
end)

I actually want to make it like this:

local function processReceipt(receiptInfo)
	-- Find the player who made the purchase in the server
	local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	if player then
		-- Output what product they bought
		print(player.Name .. " just bought " .. receiptInfo.ProductId)
		boughtLifeEvent:FireClient(player)
		
		-- IMPORTANT: Tell Roblox that the game successfully handled the purchase
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end

I just need to call the boughLifeEvent but I cant get the player name that have the gamepass, anyone know how to get the player that have the gamepass?

The checkifowngamepass event:

local Checkifowngamepass = game.ReplicatedStorage.Remotes.CheckIfOwnGamepass
local player = game.Players.LocalPlayer

Checkifowngamepass.OnClientEvent:Connect(function()
	player.PlayerGui.MainGui.Died.Visible = false
end)

https://developer.roblox.com/en-us/api-reference/function/MarketplaceService/UserOwnsGamePassAsync

This should suffice. Is there any reason why you couldn’t user this?

Uh because there is another script which make everytime someone ded, there will be a ui like a story game in normal, this is for the inf live gamepass. so I want to make the ui gone with the boughLifeEvent, but I cant get the player.
*I need the player so I can do it like this:
boughtLifeEvent:FireClient(player) --cant get the player that own the gamepass

I Solved it!
I just used, repeat wait until the ui get visible, then turn it not visible!