Help with instant respawn gamepass

local Gamepass = 703428408

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

game.Players.PlayerAdded:connect(function(Player)
	
	Player.CharacterAdded:connect(function(Character)
		
		repeat task.wait() until Character.Humanoid
		
		Character.Humanoid.Died:connect(function()
			
			if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, Gamepass) then
				
				Player:LoadCharacter()
				
			end
		end)
	end)
end)

anyone know why this isn’t working and if you do can you help me fix it so that it does? correct person gets solution

2 Likes

hello . I am currently outside. is there any errors?

nothing in the output limit limit

I think constatly checking this will flood requests I recommended checking it once then create a boolean to identify if the player had the gamepass

2 Likes

you can try debugging by adding prints when the character dies, when the player have gamepass .

1 Like

i debugged by using prints and turns out it works but it doesnt work in studio for some reason

i do have a question though if someone buys this in-game do they get the instant respawn straight away?

like if i were to buy it in the game from a prompt or something. would i instantly get the instant respawn?

1 Like

it should since you do the check every time the player dies . however, this method is kinda expensive for the performance and i would recommend checking if the player own the gamepass and if yes , then detect if the player dies

1 Like

like this? if i did something wrong could you tell me

local GamepassID = 703396350

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

game.Players.PlayerAdded:connect(function(Player)
	
	Player.CharacterAdded:connect(function(Character)
		
		if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassID) then
			
			repeat task.wait() until Character.Humanoid

			Character.Humanoid.Died:connect(function()
				
				Player:LoadCharacter()
				
			end)
			
		end
		
	end)
	
end)
1 Like

I dont know why I always see code backwards from how it’s presented to me but…

Why don’t you simply have the section of code that detects “player.HP = 0” do a “check for gamepass” and then simply “Respawn timer -60 seconds” or whatever it is prior to the death event.

it is still kinda the same . you should check if the player own the gamepass when they just join . it will improve performance but might require more scripting to check if the player buys the gamepass when playing the game

eg)

game.Players.PlayerAdded:Connect(function(plr)

if player own gamepass then

plr.CharacterAdded:Connect(function(char)
--do things
end)

end

end)

sorry if the script look weird. I dont have studio open rn

ok this is what i have now if i messed up could you correct me again? also i get what you’re saying now its better to check if they even have the gamepass before detecting if they die its better for performance

edit: i tested and it works

local GamepassID = 703396350

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

game.Players.PlayerAdded:Connect(function(Player)

	if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassID) then

		Player.CharacterAdded:Connect(function(Character)
		
			Character.Humanoid.Died:connect(function()
				
				Player:LoadCharacter()
				
			end)
		
		end)

	end

end)
1 Like

the gamepass id leads to a place
bro


whuts this??
your code was correct but the id was the wrong id
nvm

Pretty sure this script will work, it’s just that LoadCharacter is a yielding function which will wait for other scripts that are using the character.

you replaced the place id with a gamepass id of course it did that lol if you wanted to see what place the gamepass belongs to replace a gamepass id with the id im using

my bad
i used library i never used library to get an gamepass

1 Like

Also, please change :connect() to :Connect().

i didnt even notice i did that ty for telling me

just wondering did you fix the code?

yeah i fixed it but i was just waiting from a response from @skyblox7862 to see what she thinks if the new code

1 Like

mark as a solution one of your messages or someone from here that actually helped

1 Like