EDIT Ok I think I may have figured it out but I'm still testing it. my new code is this:
1 | player.CharacterAppearanceId = player.UserId |
2 | player:LoadCharacter() |
the character must be loaded afterwards but I'm still testing to see if it will fully work. so far, so good
So basically in the game I'm making, a player's model is changed depending on which type of character they have equipped. I want to morph them into the character they chose but when looking online for an R15 morph script I was unable to find one that worked. When they are teleported into the playing area I was able to override their appearance with this code:
This code removes all accessories and then changes the appearance and skin color with a function I made. It isn't the problem, but this is something I want to avoid because if this is the only way then I'll have to save each players' accessories and load them which will be very annoying
01 | ---remove all accessories |
02 | local pants = player.Character:FindFirstChild( "Pants" ) |
03 | if pants then |
04 | pants:remove() |
05 | end |
06 | local shirt = player.Character:FindFirstChild( "Shirt" ) |
07 | if shirt then |
08 | shirt:remove() |
09 | end |
10 | local tshirt = player.Character:FindFirstChild( "Shirt Graphic" ) |
11 | if tshirt then |
12 | tshirt:remove() |
13 | end |
14 |
15 | local everythingElse = player.Character:GetChildren() |
This works however, when they are teleported back into the lobby, I can't quite get their appearance to change back to what it normally was with this code:
1 | --reset appearance |
2 | for i, player in ipairs (game.Players:GetChildren()) do |
3 | player.CharacterAppearanceId = player.UserId |
4 | print ( "reset" ) |
5 | end |
Basically I'm just asking if there is a way to reset the user's character to their original model without having to reset them. Kind of like a way to morph them into a certain character that you have saved. If anyone has an idea please let me know, thanks.
Okay so I tried using Roblox api but I saw TheeDeathCaster comment and now I have two ways to do it I will post the both
Both is test.Only for the first one with local test players like Player1 etc not work.
Note.
Instead of using that code to remove stuff use the player api.
player:ClearCharacterAppearance()
Read more https://wiki.roblox.com/index.php?title=API:Class/Player/ClearCharacterAppearance
First option
Thanks to TheeDeathCaster for GetCharacterAppearanceAsync
01 | --Use this instead of that custom function make sure to get the player instance. |
02 | --E.g local player = game.Players.PlaasBoer That will get my player. |
03 |
04 | player:ClearCharacterAppearance() |
05 |
06 | --This function reset appearance when called. |
07 | --This function will add the player appearance just pass the player through the argument when using it. |
08 | function loadCharacterAppearance(player) |
09 | if player.UserId then |
10 | local theModel = game.Players:GetCharacterAppearanceAsync(player.UserId) |
11 | for _, child in pairs (theModel:GetChildren()) do |
12 | player:LoadCharacterAppearance(child) |
13 | end |
14 | end |
15 | end |
Second option
Instructions Add folder name Characters to game.ServerStorage
01 | --This will add the character model to folder name Characters in ServerStorage |
02 | game.Players.PlayerAdded:Connect( function (player) |
03 | player.CharacterAdded:Connect( function (character) |
04 | if game.ServerStorage.Characters:FindFirstChild(player.Name) = = nil then |
05 | character.Archivable = true |
06 | wait( 2 ) |
07 | character:Clone().Parent = game.ServerStorage.Characters |
08 | end |
09 | end ) |
10 | end ) |
11 |
12 | --When player leaves game this will remove the character model so that game don't use too much space |
13 | game.Players.PlayerRemoving:Connect( function (player) |
14 | local playerCharacter = game.ServerStorage.Characters:FindFirstChild(player.Name) |
15 |
You can use an outside script to reset this script or just put it in starter pack if it is local so when he die or reset the character will have this script running again Disabled is the property of a Script disable a script and then undisable it and it will run again.