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

How do I make a startercharacter/npc have the same skincolor as the person playing the game?

Asked by 2 years ago
Edited 2 years ago

**My current code is - **

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Skin = char:WaitForChild("Body Colors")

local SkinTarget = game.StarterPlayer.StarterCharacter

local skinTargeted = SkinTarget:FindFirstChild("Body Colors")

skinTargeted:Destroy()
Skin.Parent = SkinTarget

** I'm not sure what I did wrong.**

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

I'm back, and I might have a solution!

Before that, this post literally made me have to go to the developer page on Roblox. You are 100% getting an upvote!

So, upon closer inspection... I couldn't find a solution. BUT! That was yesterday me! I have learnt about setting characters. e.g:

plr.Character = game.ServerStorage.blahblahblah

SO!

With this information in mind, we can get the player's body colors, then get the starter character, and we're good to go!

Pop your starter character inside ServerStorage, insert a script inside ServerScriptService, and make SURE your starter character is called, well, StarterCharacter. What else? Anyhow...

Once you do all that we can enter our script inside ServerScriptService and do some very tiny modifications to your code. (Also, Roblox keeps closing Roblox Studio on me for no reason, so please tell me if you have any problems.)

-- local plr = game.Players.LocalPlayer -- game.Players.LocalPlayer won't work on a script, so just keep this out.

game.Players.PlayerAdded:Connect(function(plr) -- Fires when a player joins, gets the player argument.
    local char = plr.Character or plr.CharacterAdded:Wait() -- You already added this in, so I will assume you already know what this does.
    local Skin = char:WaitForChild("Body Colors") -- Same as the line above. ^

    local SkinTarget = game.ServerStorage.StarterCharacter -- Gets the StarterCharacter, but this time from ServerStorage

    local skinTargeted = SkinTarget:FindFirstChild("Body Colors") -- Finds the Body Color inside the SkinTarget; if none is found, no problem.
    if skinTargeted then -- Checks if skinTargeted actually exists, only use this when you have a :FindFirstChild() thing.
        skinTargeted:Destroy() -- Destroys the Body Color inside the SkinTarget
    end
    Skin.Parent = SkinTarget -- Parents the Player's Body Color to SkinTarget
    SkinTarget.Parent = workspace -- Puts our SkinTarget in the workspace
    plr.Character = SkinTarget -- And finally, set the skin target as our player.
end)

With all that said and done, I hope it works for you. [i would add a fingers crossed emoji here but it doesnt work]

Bye!

Ad

Answer this question