I’m trying to make a script that gives a certain player a custom character.
I’ve looked around everywhere (devforums, scripthelpers) for solutions, and also asked some friends about it and I ended up with this:
game.Players.PlayerAdded:Connect(function(player)
local char = game.ServerStorage.CustomCharacter
if player.UserId == 2983919658 then -- change the id to yours
player.Character = char:Clone()
player:LoadCharacter()
end
end)
There are no errors in the Output, but the character isn’t given to the player.
Could anybody help?
You will probably want to create a custom character loading system.
There is one on the DevHub which works well.
-- Stop automatic spawning so it can be done in the "PlayerAdded" callback
game.Players.CharacterAutoLoads = false
local respawnDelay = game.Players.RespawnTime
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)
If you are not using a custom rig you can convert the Character to a HumanoidDescription and then do Player:LoadCharacterWithHumanoidDescription()
You will find that Changing the Player.Character to another rig will kill the player because there are two humanoids. The way around it is to simply delete the Humanoid in the target destination. Switch the character then add the Humanoid after.
Oh and if you are using a custom character instead of loading the character you want to spawn the model then change the players character to the model.