Part not getting color from SurfaceLight

Hello, I am trying to script something so the part will have the same color as a light.
When you changed the color of the light it should automatically change the color of the part. But it’s not changing the color.

while true do
	script.Parent.Color = script.Parent.SurfaceLight.Color

As you can see this is a simple loop.

If you’re not getting any errors, I’m assuming that the script that changes the color is client-side. If a client or LocalScript attempts to change something, only that player/client will see that change. This means the server script won’t detect the color change. Otherwise, it could just be that you’re not waiting for everything to load.

Either way, I’d recommend using an event instead of a loop. Example:

local part = script.Parent
local light = part:WaitForChild('SurfaceLight')
	part.Color = light.Color

For fun, you can add this to the bottom of that script to see it in action:

--Rainbow lights
local speed = 0.2
local T = game:GetService('TweenService')
function tween(o,t,l,s,d)
	if not s then s = Enum.EasingStyle.Linear end
	if not d then d = Enum.EasingDirection.InOut end
	local i =,s,d)
	return T:Create(o,i,t)
local colors = {,0,0),,1,0),,1,0),,1,1),,0,1),,0,1)}
	for _,v in pairs(colors) do
until false

(Ignore that I’m using an entire tween function for one basic tween, I always use it.)

1 Like