This is exactly what I need, but I have no idea how to implement it. Can you help me implement it?
UPDATE: I am not asking for complete scripts but rather a more detailed description or some code that will allow me to understand how to implement this.
You can use functions through a Server script like Player:LoadCharacter() to load the players character.
After you load the character, you can then proceed to set their spawn location using CFrames and other things.
Then you can load their apperance after they spawn in. I tend to make API Modules for these kinds of situations since multiple scripts tend to use the player’s character but this may vary depending on what you intend to use the player’s character for!
When you spawn the character by setting player.Character you must connect to the Died event on the humanoid in that character to know when to restart the custom spawn process (i.e. when to set player.Character again after some respawn delay). Do this on the server.
This should work if you don’t do anything weird like deleting Humanoids.
Ran into this issue recently so I wanted to give an answer that worked for me, there isn’t much documentation for avatar loading order so I hope this helps.
The most important thing to know is when assigning the .Character property, it has to be done in this order:
Clone Character model
Assign Player.Character to model
Parent model to workspace
Example implementation of Roblox respawn logic:
local Players = game:GetService("Players")
local OurCharacter : Model = script.StarterCharacter
local SpawnCFrame : CFrame = CFrame.new(0,10,0) -- Where we spawn
local function OnPlayerAdded(Player : Player)
local CharacterModel : Model -- Player's character
local DieConnection : RBXScriptConnection -- Detect when we die
local function LoadCharacter()
if DieConnection then -- Disconnect old connections
DieConnection:Disconnect()
DieConnection = nil
end
if Player.Character then -- Unload previous character
Player.Character = nil -- Unassign character before destroying.
CharacterModel:Destroy() -- Destroy old character
end
CharacterModel = OurCharacter:Clone() -- Path to CharacterModel
CharacterModel:PivotTo(SpawnCFrame) -- Move to where we want to spawn
Player.Character = CharacterModel -- Assign Player.Character before Parenting.
DieConnection = CharacterModel.Humanoid.Died:Connect(function()
if DieConnection then -- Disconnect
DieConnection:Disconnect()
DieConnection = nil
end
task.wait(3) -- Waiting the respawn time
LoadCharacter() -- Reloading the character
end)
CharacterModel.Parent = workspace -- Parent character model to workspace
end
LoadCharacter()
end
Players.PlayerAdded:Connect(OnPlayerAdded)