Script for button wont work

I made a script for a button that im using for my ride and it only turns on not off when it works when i set it to do nothing why is this
here is my script

local state = false
function on()
script.Parent.BrickColor = BrickColor.new ("Lime green")
	script.Parent.Parent.Parent.Parent.Parent.Cart.one.Cart.Car1.Anchored = false
	script.Parent.Parent.Parent.Parent.Parent.Cart.one.Cart.Car1.BodyVelocity.velocity = Vector3.new(0, 6, 0)
	script.Parent.Parent.Parent.Parent.Parent.Cart.one.Cart.Car2.Anchored = false
	script.Parent.Parent.Parent.Parent.Parent.Cart.one.Cart.Car2.BodyVelocity.velocity = Vector3.new(0, 6, 0)	
end
function off()
	script.Parent.BrickColor = BrickColor.new ("Institutional white")
	script.Parent.Parent.Parent.Parent.Parent.Cart.one.Cart.Car1.Anchored = true
	script.Parent.Parent.Parent.Parent.Parent.Cart.one.Cart.Car1.BodyVelocity.velocity = Vector3.new(0, 0, 0)
	script.Parent.Parent.Parent.Parent.Parent.Cart.one.Cart.Car2.Anchored = true
	script.Parent.Parent.Parent.Parent.Parent.Cart.one.Cart.Car2.BodyVelocity.velocity = Vector3.new(0, 0, 0)	
end






local function OnClick(player)
	if state == false then
		on()
			local state = true
		
		
		
		

	else
	
		local state = false
		
	
		
	end

end

	                           
script.Parent.ClickDetector.MouseClick:connect(OnClick)
1 Like

You are not calling the off function.

2 Likes

oh i completely missed that i admit im a very bad scripter thx for the help

2 Likes