I am working on a trailer filming system for my Backrooms game and am currently trying to make the transition from normal to blackout and made this function to toggle a specific light
function lightOff(data)
currentLight = game.Workspace.Map.Lights:FindFirstChild("Light"):HasTag(data)
currentLight.Color = Color3.fromRGB(124, 112, 89)
currentLight.SurfaceLight.Enabled = false
end
But when I use the function it does nothing and stops the script. I know the data variable is correct and have double checked that.
you have to use tables for this, HasTag for one object is not enough to disable or turn on some of them, use this, and keep in mind that this
local ColorStates = {true = Color3.new(1,1,1),false = Color3.new(0,0,0)}
local function light(state:Boolean)
local Lights = workspace.Lights:GetChildren()
local chosen = Lights[math.random(1,#Lights)]
if chosen.SurfaceLight.Enabled ~= state then
chosen.Color = ColorStates[state]
chosen.SurfaceLight.Enabled = state
else
light(state)
end
end
I don’t know how to do that. The issue is that the function I made breaks when it tries to select the light with the “trailer02” tag. I just want it to do that successfully.
HasTag returns true or false if the Instance has the tag.
You could do something like this:
function lightOff(data)
for _, light in ipairs(game.Workspace.Map.Lights) do
if light:HasTag(data) then
light.Color = Color3.fromRGB(124, 112, 89)
light.SurfaceLight.Enabled = false
break
end
end
end
soo why you have to find it with specific tag???, use loop for that or without it, collection service will do the job returning you table of instances, if it’s only one object, then collection service will return only it
function lightOff(data)
for _, light in CollectionService:GetTagged(data) do
light.Color = Color3.fromRGB(124, 112, 89)
light.SurfaceLight.Enabled = false
end
end