Red line under onTouchEnded

Hi!
I have had a red line under onTouchEnded on my door script, and I don’t know how to fix it. its probably a simple solution, so please tell me if I did something wrong.
its also messing up my script, and putting this error in the output:
2021-06-01 (2)
Here is the script:

local Open = script.Parent
local Door1 = script.Parent.Parent.Door1
local Door2 = script.Parent.Parent.Door2
local IsTouched = false
local RESET_SECONDS = 1

local function onTouch(hit)
	local sound = script.Parent.OpenSound

	local humanoid = hit.Parent:FindFirstChild("Humanoid")
		
	for i,v in pairs(Door1:GetChildren()) do 
		v.Transparency = 1
		v.CanCollide = false			
	end
	
	for i,v in pairs(Door2:GetChildren()) do 
			v.Transparency = 0
			v.CanCollide = true
		
		if humanoid and not sound.IsPlaying and 
			Door2.Door.Transparency == 1
		then
			sound:Play()
	end
end

local function onTouchEnded(hit)
	local sound = script.Parent.CloseSound
	
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
		
	for i,v in pairs(Door2:GetChildren()) do 
		v.Transparency = 1
		v.CanCollide = false
	end

	for i,v in pairs(Door1:GetChildren()) do 
		v.Transparency = 0
		v.CanCollide = true		
	end
		if humanoid and not sound.IsPlaying and 
			Door2.Door.Transparency == 1
		then
			sound:Play()	
		end	
	end
end
	Open.TouchEnded:Connect(onTouchEnded) -- this is the problem
	Open.Touched:Connect(onTouch)

	wait(RESET_SECONDS) 

Your function is local under the scope of your onTouch function… move it outside

local Open = script.Parent
local Door1 = script.Parent.Parent.Door1
local Door2 = script.Parent.Parent.Door2
local IsTouched = false
local RESET_SECONDS = 1

local function onTouch(hit)
	local sound = script.Parent.OpenSound

	local humanoid = hit.Parent:FindFirstChild("Humanoid")

	for i,v in pairs(Door1:GetChildren()) do 
		v.Transparency = 1
		v.CanCollide = false			
	end

	for i,v in pairs(Door2:GetChildren()) do 
		v.Transparency = 0
		v.CanCollide = true

		if humanoid and not sound.IsPlaying and 
			Door2.Door.Transparency == 1
		then
			sound:Play()
		end
	end
end

local function onTouchEnded(hit)
	local sound = script.Parent.CloseSound

	local humanoid = hit.Parent:FindFirstChild("Humanoid")

	for i,v in pairs(Door2:GetChildren()) do 
		v.Transparency = 1
		v.CanCollide = false
	end

	for i,v in pairs(Door1:GetChildren()) do 
		v.Transparency = 0
		v.CanCollide = true		
	end
	if humanoid and not sound.IsPlaying and 
		Door2.Door.Transparency == 1
	then
		sound:Play()	
	end	
end

Open.TouchEnded:Connect(onTouchEnded)
Open.Touched:Connect(onTouch)

wait(RESET_SECONDS)
1 Like

Thanks! it works now.

1 Like