Color3 change with variable not working

Hi! I have been staring at this code for like 30 minutes or so but I just cannot see what the problem is. I am trying to change the color of a part through a script. The variable color does work and I have checked that many times already.

Here is the code:

if color ~= nil then
	set.Color = Color3.fromRGB(color)
else
	set.Color = Color3.fromRGB(99, 95, 98)
end

Problematic code:
set.Color = Color3.fromRGB(color)

Does anyone see what I am doing wrong? Thanks in advance!

What is set?
Can’t really help without seeing the full script.

local function placeBlock()
   local item = workspace.GhostBlock

   local part = item:Clone()
   part:SetPrimaryPartCFrame(CFrame.new(posx, posy, posz))
   part.Name = 'block'
   part.Parent = workspace

  local set = part.PrimaryPart
   set.Name = "Part"

   if color ~= nil then
	   set.Color = Color3.fromRGB(color)
   else
	   set.Color = Color3.fromRGB(99, 95, 98)
   end

   set.Transparency = 0
   set.Material = "SmoothPlastic"

end

If color is already a Color3, just do:

if color ~= nil then
	set.Color = color
else
	set.Color = Color3.fromRGB(99, 95, 98)
end

Aha that was the problem, thank you! :slight_smile: