Why ontouchended is unknown?

local debounce = false
local debounce2 = false
local function onTouched(Touch)
	if Touch and debounce == false then
		script.Parent.Color = Color3.new(0, 1, 0)
		debounce = true
		local function onTouchEnded(Touch)
			if Touch and debounce2 == false then
				script.Parent.Color = Color3.new(0, 0, 0)
				debounce2 = true
			end
		end
	end
end
script.Parent.Touched:Connect(onTouched)
script.Parent.TouchEnded:Connect(onTouchEnded)

You defined the local function onTouchEnded inside the scope of onTouched. That means you can call it only inside the scope of onTouched.
In order to be able to call it in all scopes, you need to define it for example under onTouched.

1 Like

I put else but it’s still unknown

local debounce = false
local debounce2 = false
local function onTouched(Touch)
	if Touch and debounce == false then
		script.Parent.Color = Color3.new(0, 1, 0)
		debounce = true
		else
		local function onTouchEnded(Touch)
			if Touch and debounce2 == false then
				script.Parent.Color = Color3.new(0, 0, 0)
				debounce2 = true
			end
		end
	end
end
script.Parent.Touched:Connect(onTouched)
script.Parent.TouchEnded:Connect(onTouchEnded)

That doesn’t change anything. I meant that you have to define it like this:

local function onTouch()

end

local function onTouchEnded()

end

onTouchEnded has to be defined in the same scope as where you connect it to an event.

1 Like

oh ok ty bro that worked

aaaaa

1 Like