"Unable to cast value to object" when trying to tween my lights

I am not sure what is wrong…

My code:

LightsOn=script.Parent.LightsOn
local tweenInfo = TweenInfo.new(5)
local TweenService = game:GetService("TweenService")

local Rooflights = {}
local function FindRoofLights(obj)
	for _, child in pairs(obj:GetChildren()) do
		if child:IsA("Light") then
			table.insert(Rooflights, child)
		end
		FindRoofLights(child)
	end
end
FindRoofLights(script.Parent.Lights.BlueRoofLights)

local function OnClick()
	for _, light in pairs(Rooflights) do
		local TweenValue = 
			{
			Brightness  = 9.84;
			}
		local tween = TweenService:Create(light, tweenInfo, TweenValue)
		tween:Play()
		end
	end

LightsOn.ClickDetector.MouseClick:connect(OnClick)

I get the error: Unable to cast value to Object

Any help will be greatly appreciated. Thank you!

2 Likes

you need set the starting color to the current light color and the ending color to a desired brightness level (full brightness in this example).

Please note that this method will only work for PointLights, SpotLights, and SurfaceLights. If you’re trying to tween other types of lights, additional modifications might be required.

Feel free to adjust the tween duration (tweenInfo.new(5)) and the endingColor values (Color3.new(1, 1, 1)) according to your preferences and requirements.

I think this should work if not then i dont know. feel free to correct me if im wrong

local TweenService = game:GetService("TweenService")

local Rooflights = {}

local function FindRoofLights(obj)
    for _, child in pairs(obj:GetDescendants()) do
        if child:IsA("Light") then
            table.insert(Rooflights, child)
        end
    end
end

FindRoofLights(script.Parent.Lights.BlueRoofLights)

local function OnClick()
    for _, light in pairs(Rooflights) do
        local startingColor = light.Color
        local endingColor = Color3.new(1, 1, 1) -- Adjust the brightness by modifying the RGB values (1, 1, 1 = full brightness)
        
        local tweenInfo = TweenInfo.new(5)
        local tween = TweenService:Create(light, tweenInfo, {Color = endingColor})
        tween:Play()
    end
end

script.Parent.LightsOn.ClickDetector.MouseClick:Connect(OnClick)

this just changes the colour of the lights not the brightness of them

UPDATE: I got it working, really dumb mistake by me the lights were just disabled. My bad, sorry for being an idiot… :grimacing:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.