Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make this respawn gamepass work?

I've made a gamepass that is supposed to make it so that when it's purchased you will get a faster respawn time, when it comes to marketplace scripts I'm not very good at them so could someone help me?

local MarketplaceService = game:GetService("MarketplaceService")
local player = game:GetService("Players")
local id = 971827976	

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		if MarketplaceService:UserOwnsGamePassAsync(player.UserId, id) then
			repeat wait() until chr.Humanoid
			chr.Humanoid.Died:Connect(function()
				wait(.3)
				plr:LoadCharacter()
		end)
	end
end)

3 comments

0

I believe you cannot do :LoadCharacter() after a player has died. Someone correct me if i'm wrong. might wanna look into this https://developer.roblox.com/en-us/api-reference/property/Players/RespawnTime?

0

You actually can call :LoadCharacter() on a Player that has died. And that link only shows you how to modify the respawn time for all players, not an individual one, as this gamepass seeks to achieve.

0

Are you getting any errors when this script runs?

1 answer

✓ Accepted answer

When using CharacterAdded event don't use the player variable.

local MarketplaceService = game:GetService("MarketplaceService")
local player = game:GetService("Players")
local id = 971827976    

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(chr)
        if MarketplaceService:UserOwnsGamePassAsync(game.Players:FindFirstChild(chr.Name).UserId, id) then
            repeat wait() until chr.Humanoid
            chr.Humanoid.Died:Connect(function()
                wait(.3)
                plr:LoadCharacter()
           end)
        end
    end)
end)

8 comments

0

Using the player variable is perfectly legitimate, why wouldn't it be?

0

i really dont know either I had same issue like this before but then I thought of another way to get the player by using the character's name and boom it worked.

0

P0vd I got an error of

0

15:22:49.291 - ServerScriptService.Script:14: Expected 'end' (to close 'function' at line 5), got

0

i simply modified your code

0

but here i fixed it should work now accept if it does

0

Ok I'll try later I'm doing something right now: D

0

ok bruh i need you to accept it

This discussion is preserved as it was. New answers, comments, and votes are closed.