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?
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
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
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?