-- Must have hopped on a segway

SegwayObject.Changed:connect(function()
	if SegwayObject.Value ~= nil and SegwayObject.Value.Parent then
		
		if UserInputService.VREnabled then
			Camera.CameraType = "Scriptable"
		else
			Camera.CameraType = "Follow"
		end
		Lights = SegwayObject.Value:WaitForChild("Lights")
		Notifiers = SegwayObject.Value:WaitForChild("Notifiers")
		Character = Player.Character
		Humanoid = Character:WaitForChild("Humanoid")
		PlayerGui = Player.PlayerGui
		SitListener = Humanoid.Seated:connect(function()Hopoff()end)
		JumpListener = UserInputService.JumpRequest:connect(function()Hopoff()end)
		ConfigLights:FireServer(0,"Cyan",true,"Neon",Lights,Notifiers)
		CheckMobile()
		CheckVR()
		IsOnSegway = true

		ContextService:BindActionAtPriority("segInputAction",onGENInput,false,2100,
			Enum.KeyCode.Space,
			Enum.KeyCode.Backspace,
			Enum.KeyCode.ButtonA,
			Enum.KeyCode.W,
			Enum.KeyCode.Up,
			Enum.KeyCode.ButtonR2,
			Enum.KeyCode.S,
			Enum.KeyCode.Down,
			Enum.KeyCode.ButtonL2,
			Enum.KeyCode.D,
			Enum.KeyCode.Right,
			Enum.KeyCode.A,
			Enum.KeyCode.Left
		)
	end
end)

SetGuiButtons()

while game:GetService("RunService").Stepped:wait() do
	
	-- Update segway's bottom direction
	CastToGround()
	
	if SegwayObject.Value and SegwayObject.Value.Parent and SeaterObject.Value and Thruster.Value and TiltMotor.Value then
	
		-- Move segway
		Accelerate()
			
		-- Update the sound
		Sound()
			
		-- Tilts the segway
		Tilt()
		UpdateVRPos()
	end
	
end