Why does my script not run anymore?

Hello, I currently am working on a “Flashlight Script”. What I had was a flashlight that you could interact with using a proximity prompt and afterwards the Handler script would register that the player interacted with the proximity prompt and enable the “Flashlight Script”. Unfortunately the script doesnt register the player using the flashlight. I would also like to add that the Disabled flashlight script is a child of the Handler script. Here is the Handler script :

local FS = script:WaitForChild("FlashlightScript")
local Flashlight = workspace:WaitForChild("Flashlight")

local function Del()
	print("function ran")
	for i = 1,100 do
		Flashlight.Bulb.Transparency += 0.01
		Flashlight.Transparency += 0.01
		wait(0.01)
	end
	Flashlight:Destroy()
end

while true do
	for i = 0,1 , 0.1 do
		Flashlight.PointLight.Brightness += 0.1
		wait(0.01)
	end
	wait(1)
	for i = 0,1 , 0.1 do
		Flashlight.PointLight.Brightness -= 0.1
		wait(0.01)
	end
	wait(1)
end

Flashlight.ProximityPrompt.Triggered:Connect(function(player)
	FS.Enabled = true
	Del()
end)

Could someone please help? I do not know what could be the issue here.
Thank you for your time.

Put this part

Flashlight.ProximityPrompt.Triggered:Connect(function(player)
	FS.Enabled = true
	Del()
end)

before the while true loop

The loop goes on forever, which makes it so the proximity prompt trigger is never connected to the function.

Thanks! That worked out perfectly

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