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

How do I make a player respawn instantly?

Asked by
snewo12 72
5 years ago

So I've made this script:

script.Parent.Touched:connect(function(part)
    if part.Parent and game:GetService('Players'):GetPlayerFromCharacter(part.Parent) then
        local player = game:GetService('Players'):GetPlayerFromCharacter(part.Parent)
        if player:GetRankInGroup(3200799) < 300 then
            local humanoid = part.Parent:FindFirstChild("Humanoid")
            humanoid.Health = 0
            end
    end
end)

but I want the player to respawn instantly, how do I do that?

0
listen to the died event (from humanoid), set characterautoloads (option in players) to false, and do player:LoadCharacter() User#20388 0 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

You can use the function LoadCharacter to force the player to respawn.

local plrServ = game:GetService('Players')
script.Parent.Touched:connect(function(hit)
    local plr = plrServ:GetPlayerFromCharacter(hit.Parent)
    if plr and plr:GetRankInGroup(3200799) < 300 then
        plr:LoadCharacter()
    end
end)

I hope this helps

0
Thank you snewo12 72 — 5y
0
game.Players.PlayerAdded:connect(function(plr) plr.CharacterAdded:connect(function(chr) repeat wait() until chr.Humanoid chr.Humanoid.Died:connect(function() plr.LoadCharacter() end) end) end)? User#30793 0 — 4y
Ad

Answer this question