Touch trigger part not working

Hello,

So I’m making it to where when you touch the trigger, the lights flicker a bit but for some reason the trigger isn’t working when touched?

Here’s a clip of what’s going on:

The black part that you can see next to the light is the trigger that is supposed to make the light flicker after touching it. For some reason though when I walk up to it, it does nothing. I’ve already checked the output to see if there was any errors and strange enough there wasn’t.

Here’s how things are set up:

In Workspace
image

The code inside the script:

local trigger = script.Parent
local light = script.Parent.Parent.Base.PointLight
local brightness = script.Parent.Parent.Base.PointLight.Brightness
local glass = script.Parent.Parent.glass
local transparency = glass.Transparency
local Debounce = false


trigger.Touched:Connect(function(hit)
	if not Debounce then
		if hit.Parent:FindFirstChild("Humanoid") then
			Debounce = true
			transparency = 0.2
			brightness = 0.4
			wait(1)
			transparency = 0.4
			brightness = 0.3
			wait(1)
			transparency = 0.6
			brightness = 0.2
			wait(1)
			transparency = 0.8
			brightness = 0.1
			wait(1)
			transparency = 0.2
			brightness = 0.4
			wait(1)
			transparency = 0.4
			brightness = 0.3
			wait(1)
			transparency = 0.6
			brightness = 0.2
			wait(1)
			transparency = 0.8
			brightness = 0.1
			wait(1)
			script:Destroy()
		end
	end   
end)

Not so sure what I’m doing wrong, I’d appreciate anyone who could be kind enough to guide me through or explain a bit!

A simple mistake here, your brightness variable is not the actual PointLights brightness property and is storing the brightness (number) value of the PointLight (as well as your transparency variable). Here is your fixed code. If you have questions or errors with this code, please ask.

local trigger = script.Parent
local light = trigger.Parent.Base.PointLight
local glass = trigger.Parent.glass
local Debounce = false

trigger.Touched:Connect(function(hit)
	if not Debounce then
		if hit.Parent:FindFirstChild("Humanoid") then
			Debounce = true
			glass.Transparency = 0.2
			light.Brightness = 0.4
			wait(1)
			glass.Transparency = 0.4
			light.Brightness = 0.3
			wait(1)
			glass.Transparency = 0.6
			light.Brightness = 0.2
			wait(1)
			glass.Transparency = 0.8
			light.Brightness = 0.1
			wait(1)
			glass.Transparency = 0.2
			light.Brightness = 0.4
			wait(1)
			Transparency = 0.4
			light.Brightness = 0.3
			wait(1)
			glass.Transparency = 0.6
			light.Brightness = 0.2
			wait(1)
			glass.Transparency = 0.8
			light.Brightness = 0.1
			wait(1)
			script:Destroy()
		end
	end   
end)
2 Likes