--by Repilee 5/1/18--
--(plez no leak kthxbai)


local BMWButton = script.Parent:WaitForChild("Button")
local car = script.Parent.Parent.Car.Value
local WindowFrame = script.Parent:WaitForChild("WindowFrame")
local MainFrame = WindowFrame:WaitForChild("MainFrame")
local LightBtn = MainFrame:WaitForChild("InteriorLight")
local FL = MainFrame:WaitForChild("FL")
local FR = MainFrame:WaitForChild("FR")
local debounce = false
local RR = MainFrame:WaitForChild("RR")
local H = MainFrame:WaitForChild("Hood")
local TK = MainFrame:WaitForChild("Trunk")
local RL = MainFrame:WaitForChild("RL")

local handler = car:WaitForChild("BMWPanel_Handler")

H.MouseButton1Down:connect(function()
	handler:FireServer("Hood")
end)

FL.MouseButton1Down:connect(function()
	if debounce == false then
		debounce = true
		handler:FireServer("Windows", "FL")
		wait(1)
		debounce = false
	end
end)
FR.MouseButton1Down:connect(function()
	if debounce == false then
		debounce = true
		handler:FireServer("Windows", "FR")
		wait(1)
			debounce = false
	end
end)
RR.MouseButton1Down:connect(function()
	if debounce == false then
		debounce = true
		handler:FireServer("Windows", "RR")
		wait(1)
			debounce = false
	end
end)
RL.MouseButton1Down:connect(function()
	if debounce == false then
		debounce = true
		handler:FireServer("Windows", "RL")
		wait(1)
			debounce = false
	end
end)

BMWButton.MouseButton1Down:Connect(function()
	if WindowFrame.Visible == false then
		WindowFrame.Visible = true
	else
		WindowFrame.Visible = false
	end
end)


LightBtn.MouseButton1Down:connect(function()
	handler:FireServer("Light")
end)

for i, btn in pairs(WindowFrame.AmbientLighting:GetChildren()) do
	if btn:IsA("ImageButton") then
		btn.MouseButton1Down:connect(function()
		handler:FireServer("AMB", btn.Name)
		end)
	end
end

TK.MouseButton1Down:connect(function()
	handler:FireServer("TK")
end)

WindowFrame.AmbientLighting.BACK.MouseButton1Down:connect(function()
	MainFrame.Visible = true
	WindowFrame.AmbientLighting.Visible = false
end)

MainFrame.AMBSettings.MouseButton1Down:connect(function()
	MainFrame.Visible = false
	WindowFrame.AmbientLighting.Visible = true
end)
