Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to lengthen respawn time for a character?

Asked by 7 years ago

So I had a little trouble with this. Do I delete the default [if there is one] respawn script and replace it with a new one? I want to lengthen respawn time for good reasons.

So this is my attempt. Which is in the PlayerCharacterScripts.

respawnscript = script.Parent.Respawn
respawnscript:Destroy()

script.Parent.Humanoid.Died:connect(function()
    wait(20)
    -- Apparently I have to recreate the character??
    oldchr = --THIS IS WHERE IM STUCK?
    newchr = oldchr:Clone()
    newchr.Parent = workspace
    newchr:MoveTo(spawnpoint.Position) -- Dont mind spawnpoint value
    workspace.CurrentCamera.CameraSubject = newchr
end)

Also, if there is a function to automatically respawn a character, instead of manually removing the character, and cloning it and teleporting it to a random spawn, then please tell me!

1 answer

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

There is a way to automatically respawn a character, instead of manually removing the character

Instead of doing what you're doing, there's a property of the Players service called, CharacterAutoLoads. Turn this off.

Now you have to tell the player when to load it's character. To do this, you now have to use :LoadCharacter() on the player when you want to spawn/respawn their character.

You would want to spawn their character when they join, and after they die. An example script would look like this,

-- Script in ServerScriptService

local RespawnTime = 10

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(char)
        char:WaitForChild("Humanoid").Died:wait()
        wait(RespawnTime)
        plr:LoadCharacter()
    end)

    wait(5)
    plr:LoadCharacter()
end)
Just make sure you turn off CharacterAutoLoads.

That was my script. For the wiki's script, look here.

Good Luck!

If I helped, please don't forget to accept my answer.
Ad

Answer this question