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

How do I "unload" a character?

Asked by 5 years ago

Okay so I have a working menu, and I disabled character auto loads so that you can click play and it will spawn in your character, but whenever the character dies, I don't know how to "unload" it and make it go back to the title screen. If I use :Destroy() on the character, all of the gui's that I already have will all have errors that say there is no character to localplayer.

0
put ur script in a CharacterAdded function Gameplayer365247v2 1055 — 5y

1 answer

Log in to vote
0
Answered by
tzmods 59
5 years ago

Quick Answer

You can use :LoadCharacter

Code to simulate re-spawning

01local respawnDelay = 5
02 
03game.Players.CharacterAutoLoads = false
04 
05game.Players.PlayerAdded:Connect(function(player)
06    player.CharacterAdded:Connect(function(character)
07        -- find the humanoid, and detect when it dies
08        local humanoid = character:FindFirstChild("Humanoid")
09        if humanoid then
10            humanoid.Died:Connect(function()
11                wait(respawnDelay)
12                player:LoadCharacter()
13            end)
14        end
15    end)
16    player:LoadCharacter() -- load the character for the first time
17end)

Explanation

The purpose of the code above is to manually re spawn characters instead of using AutoLoadCharacter. When the humanoid's health reaches 0 (player dies) this code will detect it and load the character after the chosen re spawn delay.

Sources

Dev Hub

0
I already know how to load a character, but how do I remove the character Coratite 30 — 5y
0
You need to use :Destroy() on the server side. Use a remote event when the char dies and have the server script :Destroy() the character. tzmods 59 — 5y
Ad

Answer this question