Math.random returns the same exact value until player leaves

Change the Color.fromRGB to Color3.new in the table.

local colors = {
	Color3.new(255, 255, 255); --white
	Color3.new(255, 94, 239); -- pink
	Color3.new(209, 203, 255); -- pastel
	Color3.new(170, 255, 255); -- cyan
}

Doing this I got it to return an RGB value instead of an HVS value

Well it does work, kinda but it does not return the colors i want from local colors =
and instead returns these
image

Try this:

L.Color = color 

-- Change the table back to the old ones with Color.fromRGB

Those are RGB values. You’re printing the values of the color. What else did you want it to print?

Yes this works, thank you! last thing, is it possible to only pick ONE color value from index instead of all four?

Just only call the color picker once instead of calling it 4 times

By putting it outside the function that creates the part and colors it? because i’ve heard that’s the only solution.

local colors = {
color1 = Color3.fromRGB(255, 255, 255);
Add more colors…
}
Sorry for no formatting, currently on mobile

You could do that yes. You can do:

local part = Instance.new("Part");
part.Name = 'Whatever!'
part.Parent = game.Workspace -- or wherever
part.Color = color
part.Position = UDim2.new(0, 0, 0, 0) -- position you want it at
part.Size = UDim2.new(0, 0, 0, 0) -- size you want it at

Nope it still picks all four colors instead of one, i’ve figured out it has to do something with local index = math.floor(Random.new():NextNumber(1, #colors)) could it be NextNumber?

image
That doesnt have anything to do with it.

That’s weird because all of the created parts turned out to be multicolored instead of one color.

Just have it only call that function once. The only way its setting the color 4 times would be calling multiple times. Try:

local debounce = false;
local color = nil;
if not debounce then
debounce = true
repeat
wait()
if not color then
color = colors[math.floor(Random.new():NextNumber(1, #colors))]
end
until color
end

Hello!

I’ve seen that your code was working fine when I ran the script in the command bar so I am not sure what you’re trying to do.

Reading further down the thread I could somewhat get what you mean

local colors = {
	Color3.fromRGB(255, 255, 255); --white
	Color3.fromRGB(255, 94, 239); -- pink
	Color3.fromRGB(209, 203, 255); -- pastel
	Color3.fromRGB(170, 255, 255); -- cyan
}

function createPart(i, dontTween)
	local SpecialMesh
	local L = Instance.new("Part")
	local index = Random.new():NextInteger(1, #colors)
	local Weld = Instance.new("Weld")
	Weld.C0 = dontTween and CFrame.new() or CFrame.new(0, -(i.Size.Y/2), 0)
	Weld.Part0 = i
	Weld.Part1 = L
	Weld.Parent = L
	if i:FindFirstChildWhichIsA("SpecialMesh") then
		local CSM = i:FindFirstChildWhichIsA("SpecialMesh"):Clone()
		CSM.Scale = CSM.Scale
		CSM.TextureId = ""
		CSM.Parent = L
	else
		SpecialMesh = Instance.new("SpecialMesh")
		SpecialMesh.MeshId = "rbxasset://fonts/torso.mesh"
		SpecialMesh.MeshType = Enum.MeshType.FileMesh
		SpecialMesh.Parent = L
		SpecialMesh.Scale = dontTween and Vector3.new(i.Size.X/1.515, i.Size.Y/1.515, i.Size.Z/1.515) or Vector3.new(i.Size.X/1.515, 1.515, i.Size.Z/1.515)
	end
	L.CanCollide = false
	L.Parent = workspace
	L.CanTouch = false
	L.CanQuery = false
	L.CFrame = i.CFrame
	L.Size = i.Size
	L.Shape = i.Shape
	L.Material = Enum.Material.SmoothPlastic
	L.Color = colors[index]
end

This should technically work, its just a modified code of what you posted, this should give the parts a random colour from the colours table when ever the function gets called

The created parts still returned multi colored. when i only want them one color.

Putting this outside the function made the parts one color, but the value is still same regardless until i leave and rejoin. putting IN the function results in mutlicoloring.

So you only want one colour for every part created? If that’s so then you just have to move the index variable outside the function and it should keep only one colour

Yes this worked also i figured out the only solution to the same color value being returned (until i rejoin ofcourse) is by giving each color a 50% chance is that possible?

You want NextInteger, not NextNumber

yes thats what im doing: local index = Random.new():NextInteger(1, #colors)