How to make touch and stop touching script

Hello, Please if anyone knows how to make this work help me, I have been trying this for a long time.

I want whenever car part touches other part it should give value = 1 but when touch ends it should give the value = 0

This script is not working, I am just showing

local part = game.Workspace.Park

local function onTouch(otherPart)
	if otherPart == part and game.Workspace.Park.first.Value == 0 then
		print("Touch started: " .. otherPart.Name)
		wait(0.1)
	game.Workspace.Park.first.Value = 1
	end
	
end

local function onTouchEnded(otherPart)
	if otherPart == part and game.Workspace.Park.first.Value == 1 then
		print("Touch ended: " .. otherPart.Name)
		wait(0.1)
	game.Workspace.Park.first.Value = 0
	end
	
end

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

image

Touch and TouchEnded for getting parts in a area isn’t the best way to go about it. Especially if it’s multiple parts at fast intervals. Above is a post that should help out with your problem

Seems like you tried to call the event on the part itself and comparing the hit object with itself, try changing the variable to:

local car = --type the car model here

and change the if statements to:

if otherPart.Parent == car and firstValue.Value == num then
-- your code here
end