Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I script a random skin color for the player?

Why is this not working? I'm trying to create a script that will give the player a random skin color on entry of the game.

colourstochoosefrom = math.random(1,2)
if colourstochoosefrom == 1 then
game.Workspace.ChildAdded:connect(function(plr)
local name = plr.Name
local playerinplayers = game.Players:FindFirstChild(plr.Name)
if playerinplayers ~= nil then
playerinplayers.CanLoadCharacterAppearance = false
plr.Head.face.Texture = "rbxassetid://28257733"
local bodycolors = Instance.new("BodyColors", plr)
bodycolors.RightArmColor = BrickColor.new("red")
bodycolors.LeftArmColor = BrickColor.new("red")
bodycolors.LeftLegColor = BrickColor.new("red")
bodycolors.RightLegColor = BrickColor.new("red")
bodycolors.TorsoColor = BrickColor.Random()
bodycolors.HeadColor = BrickColor.new("red")
end
if colourstochoosefrom == 2 then
	game.Workspace.ChildAdded:connect(function(plr)
local name = plr.Name
local playerinplayers = game.Players:FindFirstChild(plr.Name)
if playerinplayers ~= nil then
playerinplayers.CanLoadCharacterAppearance = false
plr.Head.face.Texture = "rbxassetid://28257733"
local bodycolors = Instance.new("BodyColors", plr)
bodycolors.RightArmColor = BrickColor.new("blue")
bodycolors.LeftArmColor = BrickColor.new("blue")
bodycolors.LeftLegColor = BrickColor.new("blue")
bodycolors.RightLegColor = BrickColor.new("blue")
bodycolors.TorsoColor = BrickColor.Random()
bodycolors.HeadColor = BrickColor.new("blue")
end

6 comments

1

Please format your code

0

Please format your code? How do I do that?

0

dude, when you ask a question, it says lua at the top, inside the ~~~~~~~~~ area, put your code..

0

oh ty dude

0

I re-did it

0

All I can think of rn is that you did not name the body colors correctly. I've never heard of bodycolors but if it's anything like BrickColor then you should most definitely make sure it's spelled correctly, as most everything in code is CaSe SeNsItIvE

1 answer

✓ Accepted answer

I made a table full of body colors, and then randomly chose a part color from the table, then used a for loop to put the part color on each part of the character. Hope this helps!

local players = game.Players

local changeBody = function(char, color)
	local allParts = char:GetChildren()

	for i = 1, #allParts do -- You could use the In Pairs loop, but I prefer this.
		if allParts[i]:IsA("Part") then
			allParts[i].BrickColor = BrickColor.new(color)
		end
	end
end


players.PlayerAdded:connect(function(client)
	repeat wait() until client.Character
	local character = client.Character
	local bodyColors = {"Pastel brown", "Dark stone grey"} -- A table to put the names of the part colors in.
	local randomColor = bodyColors[math.random (1, #bodyColors)] -- 1 might need to be 0. Not entirely sure.

	changeBody (character, randomColor)
end)

1 comment

0

How can I make the players have different colors?

This discussion is preserved as it was. New answers, comments, and votes are closed.