Hello,
I am trying to make system that adds Highlights to every part in workspace.
I wanted to achieve highlight color to be part color but little darker, but i got this error:
ServerScriptService.Script:13: attempt to index number with 'Color'
Script:
local parts = game.Workspace:GetDescendants()
for _, v in pairs(parts) do
if v:IsA("BasePart") then
local r1 = v.Color.R
local g1 = v.Color.G
local b1 = v.Color.B
function x(n1, n2)
return n1 - n2
end
local r = x(r1.Color.R, 50)
local g = x(g1.Color.G, 50)
local b = x(b1.Color.B, 50)
local line = Instance.new("Highlight")
line.FillTransparency = 1
line.DepthMode = Enum.HighlightDepthMode.Occluded
line.OutlineTransparency = .6
line.OutlineColor = Color3.new(r, g, b)
line.Parent = v
end
end
If is this even possible to achieve something like this?
function color3torgb(color3, decreaseamount)
return color3.R*255 - decreaseamount,color3.G*255 - decreaseamount,color3.B*255 - decreaseamount
end
line.OutlineColor = Color3.fromRGB(color3torgb(Color3.new(v.Color.R, v.Color.G, v.Color.B), 30))
-- // The 30 is the decrease amount, so how much you want to decrease the color by
Full code:
local parts = game.Workspace:GetDescendants()
function color3torgb(color3, decreaseamount)
return color3.R*255 - decreaseamount,color3.G*255 - decreaseamount,color3.B*255 - decreaseamount
end
for _, v in pairs(parts) do
if v:IsA("BasePart") then
local line = Instance.new("Highlight")
line.FillTransparency = 1
line.DepthMode = Enum.HighlightDepthMode.Occluded
line.OutlineTransparency = .6
line.OutlineColor = Color3.fromRGB(color3torgb(Color3.new(v.Color.R, v.Color.G, v.Color.B), 30))
line.Parent = v
end
end
If you’re trying to use highlights to create a cell shading effect, that would probably not be the best way to go about it. Workspace only allows up to 31 active highlight objects for performance reasons. The best way to go about this is to use inverted meshes. If you’re using just parts, all you have to do is go into blender, hit scale -1 on the basic cube, export from blender, import into roblox, and make sure double sided is off.
Yeah, you should be able to use inverted parts to do that, or you can find old roblox parts in the toolbox that still have the surface properties and just use those.
local parts = workspace:GetDescendants() -- wokspace instead of game.Workspace for more optimized code
for _, v in ipairs(parts) do
if v:IsA("BasePart") then
local r1 = v.Color.R
local g1 = v.Color.G
local b1 = v.Color.B
local d = 50
local function x(n1, n2)
return n1 - n2
end
local r = x(r1, d)
local g = x(g1, d)
local b = x(b1, d)
local line = Instance.new("Highlight", v) -- Parent it immedietely
line.FillTransparency = 1
line.DepthMode = Enum.HighlightDepthMode.Occluded
line.Outline.Transparency = 0.6
line.OutlineColor = Color3.fromRGB(r, g, b)
end
end
You can get around the 31 max by just putting a highlight object in a model object and putting all the parts you want highlighted inside kinda weird but it works.