Make the player’s Character turn into a copy of the morph.
local morph = TestRig:Clone()
morph.Parent = workspace
plr.Character = morph
However, if you do that in the if
block, then it will happen only once, when the player first joins.
There’s a good example of a custom character loading loop on the wiki:
The code in question:
local respawnDelay = 5
game.Players.CharacterAutoLoads = false
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
-- find the humanoid, and detect when it dies
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid.Died:Connect(function()
wait(respawnDelay)
player:LoadCharacter()
end)
end
end)
player:LoadCharacter() -- load the character for the first time
end)
This code is centered around character death. When a character dies, it is respawned in 5 seconds. It also creates the character initially, so that it can die and be respawned in the first place.
(Note the CharacterAutoLoads
- that is important for avoiding letting players spawn as normal.)
Let’s change this code up a bit.
When a non-ranked player joins, then they should spawn normally.
When a ranked player joins, they should spawn as a morph every time.
(I’ve made the code respawn in a loop instead of in recursive events because I think it’s cleaner)
local respawnDelay = 5
local TestRig = game.Workspace:WaitForChild("TestRig")
game.Players.CharacterAutoLoads = false
game.Players.PlayerAdded:Connect(function(player)
if player:GetRankInGroup(7411123) == 255 then
-- if true then -- uncomment this and comment the above for easier testing!
-- Ranked player respawn loop
while player.Parent do
local character = TestRig:Clone()
-- position the character here
-- and possibly transfer any startercharacterscripts from starterplayer
character.Parent = workspace
player.Character = character
-- no need to findfirstchild, if the humanoid is missing then something's gone horribly wrong anyway
local humanoid = character.Humanoid
-- wait for character to die before trying to respawn it
humanoid.Died:Wait()
-- and an extra 5 seconds
wait(respawnDelay)
end
else
-- Unranked player respawn loop
while player.Parent do
player:LoadCharacter() -- load the character for the first time
local character = player.Character or player:WaitForCharacter()
local humanoid = character.Humanoid
humanoid.Died:Wait()
wait(respawnDelay)
end
end
end)
The ranked player spawning has a couple nasty bugs, though.
One I happened upon myself is that the camera could detach from the newly added character. To fix the symptoms, set the Camera’s CameraSubject to the new Character’s Humanoid in a LocalScript (either on CharacterAdded or in a LocalScript included with the rig)
Another is that the morph probably won’t automatically get StarterCharacterScripts.
For more insight, look into any proper good morph script.
You might get better results by letting the character spawn normally, then modifying it, adding morph stuff etc., instead of changing the Character, old-style, as I did here.
Edit: I’m sure it’s possible for the loops to leak memory, since they can get stuck on waiting for a nonexistent humanoid to die when a player leaves