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)
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.
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
Its working in studio but not in roblox
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)
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