mouse.KeyDown:connect(function(c)if c=="\110"then if script.Parent.Position==UDim2.new(1,0,.5,-110)then script.Parent:TweenPosition(UDim2.new(1,-376,.5,-110),"\073\110\079\117\116","\081\117\105\110\116",.5,false)else script.Parent:TweenPosition(UDim2.new(1,0,.5,-110),"\073\110\079\117\116","\081\117\105\110\116",.5,false)end end end)for c,g in ipairs(script.Parent.CarPlay.Homescreen.Apps:GetChildren())do if g:IsA("\073\109\097\103\101\066\117\116\116\111\110")then g.MouseButton1Down:connect(function()if g.AppEnabled.Value==true then if g.Name=="\077\101\115\115\097\103\101\115"or g.Name=="\080\104\111\110\101"or g.Name=="\066\077\087"or g.Name=="\080\111\100\099\097\115\116\115"then else LaunchApp(g.Name)if g.Name=="\077\117\115\105\099"then CreatePlaylists()end end end end)end end side.HomeButton.MouseButton1Down:Connect(function()LaunchHome()end)music.Library.NowPlaying.NowPlaying.MouseButton1Down:connect(function()TransitionTo("\076\105\098\114\097\114\121","\078\111\119\080\108\097\121\105\110\103")AddRecentApp("\078\111\119\080\108\097\121\105\110\103")end)music.Playlists.Back.Back.MouseButton1Down:connect(function()TransitionTo("\080\108\097\121\108\105\115\116\115","\076\105\098\114\097\114\121")end)music.Playlists.NowPlaying.NowPlaying.MouseButton1Down:Connect(function()TransitionTo("\080\108\097\121\108\105\115\116\115","\078\111\119\080\108\097\121\105\110\103")AddRecentApp("\078\111\119\080\108\097\121\105\110\103")end)script.Parent.CarPlay.NowPlaying.Back.Back.MouseButton1Down:connect(function()AddRecentApp("\077\117\115\105\099")script.Parent.CarPlay.Music.Visible=true script.Parent.CarPlay.Music.Playlists.Visible=false handler:FireServer("\077\117\115\105\099\070\105\120")TransitionTo("\078\111\119\080\108\097\121\105\110\103","\076\105\098\114\097\114\121")CreatePlaylists()end)script.Parent.CarPlay.NowPlaying.Play.Play.MouseButton1Down:connect(function()if sound.IsPlaying==false then filter:FireServer("\114\101\115\117\109\101\083\111\110\103")handler:FireServer("\065\099\116\105\111\110","\080\108\097\121")nowplaying.Play.ImageRectOffset=Vector2.new(150,0)else handler:FireServer("\065\099\116\105\111\110","\080\097\117\115\101")nowplaying.Play.ImageRectOffset=Vector2.new(0,0)filter:FireServer("\112\097\117\115\101\083\111\110\103")end end)songData.Changed:connect(function()local c=script.Parent.CarPlay_Data.Playlists[script.Parent.CarPlay_Data.NowPlayingData.CurrentPlaylist.Value]local g=#c:GetChildren()if songData.Value==0 then songData.Value=g end if songData.Value>g then songData.Value=1 end PlayMusicUsingSongValue(songData.Value,script.Parent.CarPlay_Data.NowPlayingData.CurrentPlaylist.Value)end)script.Parent.CarPlay.NowPlaying.Rewind.Rewind.MouseButton1Down:connect(function()songData.Value=songData.Value-1 end)script.Parent.CarPlay.NowPlaying.FastForward.FastForward.MouseButton1Down:connect(function()songData.Value=songData.Value+1 end)sound.Ended:Connect(function()songData.Value=songData.Value+1 end)script.Parent.CarPlay.Maps.MapFrame.Overview.MouseButton1Down:connect(function()TransitionTo("\077\097\112\070\114\097\109\101","\079\118\101\114\118\105\101\119")end)script.Parent.CarPlay.Maps.Overview.Back.Back.MouseButton1Down:connect(function()TransitionTo("\079\118\101\114\118\105\101\119","\077\097\112\070\114\097\109\101")end)script.Parent.CarPlay.BMW.SettingsHome.Back.Back.MouseButton1Down:connect(function()LaunchHome()end)script.Parent.CarPlay.Settings.SettingsHome.Back.Back.MouseButton1Down:connect(function()LaunchHome()end)script.Parent.CarPlay.Settings.SettingsHome["\050\052\072\114\070\111\114\109\097\116"].Toggle.MouseButton1Down:connect(function()if script.Parent.CarPlay_Data.SettingsData["\050\052\072\111\117\114\070\111\114\109\097\116"].Value==true then script.Parent.CarPlay_Data.SettingsData["\050\052\072\111\117\114\070\111\114\109\097\116"].Value=false else script.Parent.CarPlay_Data.SettingsData["\050\052\072\111\117\114\070\111\114\109\097\116"].Value=true end end)script.Parent.CarPlay.Settings.SettingsHome.RecentApps.Toggle.MouseButton1Down:connect(function()if script.Parent.CarPlay_Data.SettingsData.RecentApps.Value==true then script.Parent.CarPlay_Data.SettingsData.RecentApps.Value=false else script.Parent.CarPlay_Data.SettingsData.RecentApps.Value=true end end)script.Parent.CarPlay_Data.SettingsData.RecentApps.Changed:connect(function()if script.Parent.CarPlay_Data.SettingsData.RecentApps.Value==true then RecentAppEnabled=true script.Parent.CarPlay.Settings.SettingsHome.RecentApps.Toggle.Text="\079\078"else RecentAppEnabled=false side.Status:TweenPosition(UDim2.new(.111,0,.485,0),"\073\110\079\117\116","\081\117\105\110\116",.5,true)side.B1:TweenPosition(UDim2.new(.028,0,.433,0),"\073\110\079\117\116","\081\117\105\110\116",.5,true)script.Parent.CarPlay.Settings.SettingsHome.RecentApps.Toggle.Text="\079\070\070"side.RecentApps:ClearAllChildren()end end)while wait(.5)do script.Parent.CarPlay.NowPlaying.MusicLen.Text="-"..(math.floor(sound.TimeLength/60-sound.TimePosition/60)..("\058"..math.floor(math.fmod(math.abs(sound.TimeLength-sound.TimePosition),60))))handler:FireServer("\085\112\100\097\116\101\068\117\114\097\116\105\111\110","-"..(math.floor(sound.TimeLength/60-sound.TimePosition/60)..("\058"..math.floor(math.fmod(math.abs(sound.TimeLength-sound.TimePosition),60)))))script.Parent.CarPlay.Maps.Overview.Speed.Text=math.floor(car.DriveSeat.Velocity.magnitude*.56818181818182).." \109\112\104"local c=game.PlaceId local g=(game:GetService("\077\097\114\107\101\116\112\108\097\099\101\083\101\114\118\105\099\101")):GetProductInfo(c)script.Parent.CarPlay.Maps.Overview.GameName.Text=g.Name script.Parent.CarPlay.Maps.Overview.Latitude.Text="\076\097\116\105\116\117\100\101\058 "..math.floor(antenna.Position.X)script.Parent.CarPlay.Maps.Overview.Attitude.Text="\065\116\116\105\116\117\100\101\058 "..math.floor(antenna.Position.Y)script.Parent.CarPlay.Maps.Overview.Longitude.Text="\076\111\110\103\105\116\117\100\101\058 "..math.floor(antenna.Position.Z)script.Parent.CarPlay.NowPlaying.MusicLen.Changed:connect(function()if string.len(script.Parent.CarPlay.NowPlaying.MusicLen.Text)==4 then script.Parent.CarPlay.NowPlaying.MusicLen.Text="-"..(math.floor(sound.TimeLength/60-sound.TimePosition/60)..("\058\048"..math.floor(math.fmod(math.abs(sound.TimeLength-sound.TimePosition),60))))end end)end

mouse.KeyDown:connect(function(key)
	if key == "n" then
	--	if screen:FindFirstChild("CarPlay").Visible == true then
			if script.Parent.Position == (UDim2.new(1, 0, 0.5, -110)) then
		script.Parent:TweenPosition(UDim2.new(1, -376,0.5, -110), "InOut", "Quint", 0.5, false)
			else
				script.Parent:TweenPosition(UDim2.new(1,0,0.5, -110), "InOut", "Quint", 0.5, false)
	--	end
		end
	end
end)

for i, app in ipairs(script.Parent.CarPlay.Homescreen.Apps:GetChildren()) do
	if app:IsA("ImageButton") then
		app.MouseButton1Down:connect(function()
			if app.AppEnabled.Value == true then
				if app.Name == "Messages" or app.Name == "Phone" or app.Name == "BMW" or app.Name == "Podcasts" then
				else
					LaunchApp(app.Name)
				if app.Name == "Music" then
					CreatePlaylists()
				end
				end
				end
		end)
	end
end

side.HomeButton.MouseButton1Down:Connect(function()
	LaunchHome()
end)

music.Library.NowPlaying.NowPlaying.MouseButton1Down:connect(function()
	TransitionTo("Library", "NowPlaying")
	AddRecentApp("NowPlaying")
end)

music.Playlists.Back.Back.MouseButton1Down:connect(function()
	TransitionTo("Playlists", "Library")
end)

music.Playlists.NowPlaying.NowPlaying.MouseButton1Down:Connect(function()
	TransitionTo("Playlists", "NowPlaying")
	AddRecentApp("NowPlaying")
end)

script.Parent.CarPlay.NowPlaying.Back.Back.MouseButton1Down:connect(function()
	AddRecentApp("Music")
	script.Parent.CarPlay.Music.Visible = true
	script.Parent.CarPlay.Music.Playlists.Visible = false
	handler:FireServer("MusicFix")
	TransitionTo("NowPlaying", "Library")
	CreatePlaylists()
end)

script.Parent.CarPlay.NowPlaying.Play.Play.MouseButton1Down:connect(function()
	if sound.IsPlaying == false then
		filter:FireServer("resumeSong")
		handler:FireServer("Action", "Play")
		nowplaying.Play.ImageRectOffset = Vector2.new(150, 0)
	else
		handler:FireServer("Action", "Pause")
		nowplaying.Play.ImageRectOffset = Vector2.new(0, 0)
		filter:FireServer("pauseSong")
	end
end)

songData.Changed:connect(function()
	local Playlist = script.Parent.CarPlay_Data.Playlists[script.Parent.CarPlay_Data.NowPlayingData.CurrentPlaylist.Value]
	local playlistnum = (#Playlist:GetChildren())
			if songData.Value == 0 then
		songData.Value = playlistnum
			end
		if songData.Value > playlistnum then
			songData.Value = 1
		end
		PlayMusicUsingSongValue(songData.Value, script.Parent.CarPlay_Data.NowPlayingData.CurrentPlaylist.Value)
end)

script.Parent.CarPlay.NowPlaying.Rewind.Rewind.MouseButton1Down:connect(function()
	songData.Value = songData.Value - 1
end)

script.Parent.CarPlay.NowPlaying.FastForward.FastForward.MouseButton1Down:connect(function()
	songData.Value = songData.Value + 1
end)

sound.Ended:Connect(function()
	songData.Value = songData.Value + 1
end)

script.Parent.CarPlay.Maps.MapFrame.Overview.MouseButton1Down:connect(function()
	TransitionTo("MapFrame", "Overview")
end)

script.Parent.CarPlay.Maps.Overview.Back.Back.MouseButton1Down:connect(function()
	TransitionTo("Overview", "MapFrame")
end)

script.Parent.CarPlay.BMW.SettingsHome.Back.Back.MouseButton1Down:connect(function()
	LaunchHome()
end)

script.Parent.CarPlay.Settings.SettingsHome.Back.Back.MouseButton1Down:connect(function()
	LaunchHome()
end)

script.Parent.CarPlay.Settings.SettingsHome["24HrFormat"].Toggle.MouseButton1Down:connect(function()
	if script.Parent.CarPlay_Data.SettingsData["24HourFormat"].Value == true then
	script.Parent.CarPlay_Data.SettingsData["24HourFormat"].Value = false
	else
		script.Parent.CarPlay_Data.SettingsData["24HourFormat"].Value = true
		end
end)

script.Parent.CarPlay.Settings.SettingsHome.RecentApps.Toggle.MouseButton1Down:connect(function()
	if script.Parent.CarPlay_Data.SettingsData.RecentApps.Value == true then
	script.Parent.CarPlay_Data.SettingsData.RecentApps.Value = false
	else
		script.Parent.CarPlay_Data.SettingsData.RecentApps.Value = true
		end
end)

script.Parent.CarPlay_Data.SettingsData.RecentApps.Changed:connect(function()
if script.Parent.CarPlay_Data.SettingsData.RecentApps.Value == true then	
	RecentAppEnabled = true
	script.Parent.CarPlay.Settings.SettingsHome.RecentApps.Toggle.Text = "ON"
else
	RecentAppEnabled = false
	side.Status:TweenPosition(UDim2.new(0.111, 0,0.485, 0), "InOut", "Quint", 0.5, true)
	side.B1:TweenPosition(UDim2.new(0.028, 0,0.433, 0), "InOut", "Quint", 0.5, true)
	script.Parent.CarPlay.Settings.SettingsHome.RecentApps.Toggle.Text = "OFF"
	side.RecentApps:ClearAllChildren()
end
end)

while wait(.5) do
	script.Parent.CarPlay.NowPlaying.MusicLen.Text = "-"..(math.floor(sound.TimeLength/60-sound.TimePosition/60))..":"..math.floor(math.fmod(math.abs(sound.TimeLength-sound.TimePosition),60))
	handler:FireServer("UpdateDuration", "-"..(math.floor(sound.TimeLength/60-sound.TimePosition/60))..":"..math.floor(math.fmod(math.abs(sound.TimeLength-sound.TimePosition),60)))
	script.Parent.CarPlay.Maps.Overview.Speed.Text = (math.floor(car.DriveSeat.Velocity.magnitude*((10/12) * (60/88)))).. " mph"
	local placeId = game.PlaceId
	local Asset = game:GetService("MarketplaceService"):GetProductInfo(placeId)
	script.Parent.CarPlay.Maps.Overview.GameName.Text = Asset.Name
	script.Parent.CarPlay.Maps.Overview.Latitude.Text = "Latitude: "..math.floor(antenna.Position.X)
	script.Parent.CarPlay.Maps.Overview.Attitude.Text = "Attitude: "..math.floor(antenna.Position.Y)
	script.Parent.CarPlay.Maps.Overview.Longitude.Text = "Longitude: "..math.floor(antenna.Position.Z)
	
	script.Parent.CarPlay.NowPlaying.MusicLen.Changed:connect(function()
	if string.len(script.Parent.CarPlay.NowPlaying.MusicLen.Text) == 4 then
		script.Parent.CarPlay.NowPlaying.MusicLen.Text = "-"..(math.floor(sound.TimeLength/60-sound.TimePosition/60))..":0"..math.floor(math.fmod(math.abs(sound.TimeLength-sound.TimePosition),60))
	end
end)
end
