Script not working for light flickering

I have a script that is supposed to enable and disable a PointLight, however, it doesn’t seem to work with what I’ve tried.

local triggerF = game.Workspace.triggerFlicker
local lightEnabled = game.Workspace.FlickerLight.Part.PointLight.Enabled

function onPartTouched(triggerF)
	lightEnabled = false
	wait(1)
	lightEnabled = true
end

Any help is appreciated! :slight_smile:

you’re localizing the enabled value

local triggerF = game.Workspace.triggerFlicker
local pointLight = game.Workspace.FlickerLight.Part.PointLight

function onPartTouched(triggerF)
	pointLight.Enabled = false
	wait(1)
	pointLight.Enabled = true
end

A few issues!

  1. Connecting a function (like onPartTouched) to an event (like Touched) looks like this:

    function onPartTouched(thePartThatTouchedUs)
      -- ...
    end
    triggerF.Touched:Connect(onPartTouched)
    
  2. You can’t store a reference to a property (PointLight.Enabled). You have to store the PointLight, and do what @uwuCulturist said

  3. You’ll run into issues, because this function will be called every time the part is touched, each run queuing up an additional wait(1). You should wrap the function inside an if statement that checks if the light is on:

    function onPartTouched(thePartThatTouchedUs)
      if pointLight.Enabled then
        -- ...
      end
    end
    

That’s what I was looking for!

All I needed was to add the last line. Thanks!

local Light = game.Workspace.triggerFlicker
local PART = PartPath

function onPartTouched(on)
	if on == true then
            Light.Enabled = true
       elseif on == false then
                 Light.Enabled = false
           end
      end
end

PART.Touched:Connect(function(Target)
      if Target.Parent:FindFirstChild("Humanoid") then
             onPartTouched(true)
             wait(1)
             onPartTouched(false)
       end
end)

You should mark his as solution so others can’t get confused like me, Lol :grin: