Hi, I’m trying to make it so if the leaderstats == 1 (as example), the player’s character changes to a different character model inside ServerStorage that contains Humanoid, Head etc. Also on join/or during game and if/when they die, they respawn as the updated changed character.
I’ve been testing but I’m only able to get it to work once then it no longer works if player dies/respawns. But when player dies, it keeps respawning and also respawning multiple cloned character models for some reason.
I looked on Google, YouTube and DevForum but not find a solution to this little issue.
This is the serverscript code:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
-- The Gems word is just for testing.
if plr.stats.Gems.Value == 0 then
local armor = game.ServerStorage.Armor.OverseerArmor:Clone()
armor.Name = plr.Name
plr.Character = armor
armor.Parent = workspace
plr:LoadCharacter()
end
end)
end)
You have to delete that line, it’ll start an endless loop because loadcharacter respawns the character and fires characterAdded, and when character Added is fired that function runs which reloads the character etc. That’s why it keeps repeating that function.
Are you loading a completely custom character or just a standard Roblox rig with different accessories/clothing? It looks like you are doing the later, you might want to consider LoadCharacterWithHumanoidDescription()
I’m doing something similar how StarterCharacter works.
Basically for example. If player joins server or respawns and they are Level.Value 1, they get Overseer Armor thats inside a Model like StarterCharacter and their character appearance changes to the Overseer Armor appearance.
In my Overseer Armor Model, I have the following:
Body Colours
Humanoid
Hat/Accessories
All Body Parts (Used Overseer bundle thats on the Avatar Shop)
Also if player is now Level.Value = 2, the character appearance changes from Overseer Armor to Redcliff Armor (as example)
If you are using roblox packages you should use LoadCharacterWithHumanoidDescription()
Just make a HumanoidDescription with the overseer bundle ids, place it in ServerStorage and then when the player joins do something like this:
Local description = game:GetService(“ServerStorage”).HumanoidDescritption
game.Players.PlayerAdded:Connect(function(player)
player:LoadCharacterWithHumanoidDescription(description)
end)
(Note: I just typed this up and have not checked for any bugs)
Thanks it worked! But now when I die/respawn, my character goes back to default. You know how to make it so if I die, the loaded HumanoidDescription keeps loading?
You will need to turn off CharacterAutoLoads. When you do this it will not respawn the player’s character so you will need to make your own respawn script that respawns the character with your humanoid description. At the bottom of this link here you will find an example of how to do this. You will need to change line 12 in the example from LoadCharacter() to LoadCharacterWithHumanoidDescription() for your use.