Randomized StarterCharacter

I would like to make script that randomizes character torso colors and leg colors, but I’ve tried to make a script with help from the Dev Forum in the past and I havent been able to. How would I do this?

2 Likes
-- Your character
local Character = Player.Character
-- Table of every instance inside your character
local CharacterChildren = Character:GetChildren()

-- Iterate through table
for i,v in ipairs(CharacterChildren) do
	
	-- Checks if v is a bodypart
	if v:IsA("BasePart") then

		v.Color = Color3.new(math.random(),math.random(),math.random())

	end

end
2 Likes

Would this go in ServerScripts, StarterPlayer or StarterCharacter?

1 Like

Either StarterCharacter or ServerScripts. I recommend doing it on StarterCharacter if you want the player to get a random color when they respawn.

1 Like

Maybe don’t use chatgpt

local Character = game:GetService("Players").LocalPlayer.Character

if Character then
    local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")

    local function randomizeobj(BasePart : BasePart)
        if BasePart then
            BasePart.BrickColor = BrickColor.random()
        end
    end

    if Humanoid then
        randomizeobj(Humanoid.LeftLeg)
        randomizeobj(Humanoid.RightLeg)
    end
    randomizeobj(Character:FindFirstChild("Torso"))
end
1 Like

I got the error “Character is not a valid member of ‘Players’”

1 Like

if the script is inside StarterCharacter then the Character is script.parent

local Character = Player.Character --instead of this

local Character = script.Parent -- Do this
1 Like

already fixed it I forgot to add “.LocalPlayer”

1 Like

? What is that supposed to mean?

1 Like

I’m saying you’re using chatgpt

first off your comments
second off you’re iteration is calling a table value

2 Likes

I’m not using chatgpt buddy, it’s rude to go around saying that for no good reason

1 Like

my apologizes it was not my intent to be rude.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.