Random body colors system dont working

Hello dev’s. Today i tested this script:

local bcr = math.random(1,3)

if bcr == 1 then
	game.ServerStorage.Assets.Character.BodyColor1:Clone().Parent = script.Parent
elseif bcr == 2 then
	game.ServerStorage.Assets.Character.BodyColor2:Clone().Parent = script.Parent
elseif bcr == 3 then
	game.ServerStorage.Assets.Character.BodyColor3:Clone().Parent = script.Parent
end

But, its not worked. I want random body color system.

Have a nice day. Sorry, my English not good.

If this a local script, then it cant reach ServerStorage (i dont think this is local script). Also try this:

local function GetColor()
	local Colors = {}
	
	for _, Color : BodyColors in pairs(game:GetService("ServerStorage").Assets.Character:GetChildren()) do
		if Color:IsA("BodyColors") then
			table.insert(Colors, Color)
		end
	end
	
	local Roll = tostring(math.random(1,#Colors))
	
	for _, Color : BodyColors in pairs(Colors) do
		if string.split(Color.Name, "BodyColor")[2] == Roll then
			return Color
		end
	end
end

local Clone = GetColor():Clone()

Clone.Parent = script.Parent

Tested it in my workspace, it worked (i created your environment)

1 Like

thank you so much, man!)))!!! :star_struck: :star_struck: :star_struck:

1 Like

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