Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to change character appearance without having them respawn? *EDIT*

Asked by 5 years ago
Edited 5 years ago

EDIT Ok I think I may have figured it out but I'm still testing it. my new code is this:

        player.CharacterAppearanceId = player.UserId
        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

---remove all accessories
local pants = player.Character:FindFirstChild("Pants")
if pants then
    pants:remove()
end
local shirt = player.Character:FindFirstChild("Shirt")
if shirt then
    shirt:remove()
end
local tshirt = player.Character:FindFirstChild("Shirt Graphic")
if tshirt then
    tshirt:remove()
end

local everythingElse = player.Character:GetChildren()
for i = 1, #everythingElse do
    if everythingElse[i].ClassName == "Accessory" then
        everythingElse[i]:remove()
    end
end

changeSkinColor()

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:

--reset appearance
for i, player in ipairs(game.Players:GetChildren()) do
    player.CharacterAppearanceId = player.UserId
    print("reset")
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.

0
I am working on getting solution. PlaasBoer 275 — 5y
0
I know practically nothing but just a random hunch: there is a small chance that somehow changing the character value in player to a different character could possibly change you to that character. As I said, I have really no idea. OBenjOne 190 — 5y
0
@TheeDeathCaster I think it only works for models because it says it is not a member of player sonicfan0405 18 — 5y
View all comments (3 more)
0
Try to figure it out yourself and if you really struggle too long then use my code. PlaasBoer 275 — 5y
0
Combine that with TheeDeathCaster link PlaasBoer 275 — 5y

2 answers

Log in to vote
0
Answered by
PlaasBoer 275 Moderation Voter
5 years ago
Edited 5 years ago

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

--Use this instead of that custom function make sure to get the player instance.
--E.g local player = game.Players.PlaasBoer  That will get my player.

player:ClearCharacterAppearance()

--This function reset appearance when called.
--This function will add the player appearance just pass the player through the argument when using it.
function loadCharacterAppearance(player)
    if player.UserId then
        local theModel = game.Players:GetCharacterAppearanceAsync(player.UserId)
        for _, child in pairs(theModel:GetChildren()) do
            player:LoadCharacterAppearance(child)
        end
    end
end

Second option

Instructions Add folder name Characters to game.ServerStorage

--This will add the character model to folder name Characters in ServerStorage
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        if game.ServerStorage.Characters:FindFirstChild(player.Name) == nil then
            character.Archivable = true
            wait(2)
            character:Clone().Parent = game.ServerStorage.Characters
        end
    end)
end)

--When player leaves game this will remove the character model so that game don't use too much space
game.Players.PlayerRemoving:Connect(function(player)
    local playerCharacter = game.ServerStorage.Characters:FindFirstChild(player.Name)

    if playerCharacter ~= nil then
        playerCharacter:Destroy()
    end
end)

--This function will get the character model remove current and change your player to that one and move that model cframe position to your position
function loadCharacterAppearance(player)
    local characterModel =   game.ServerStorage.Characters:FindFirstChild(player.Name):Clone()
    characterModel:SetPrimaryPartCFrame(player.Character.PrimaryPart.CFrame)

    player.Character:Destroy()
    player.Character = characterModel
    characterModel.Parent = game.Workspace
end
Ad
Log in to vote
0
Answered by
royee354 129
5 years ago

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.

Answer this question