if UserInputService.VREnabled and VRUseHeadsetControls.Value==true then VRService.UserCFrameChanged:connect(function(s,e)local n,T=e:toEulerAnglesXYZ()local G=1.2 if s==Enum.UserCFrame.Head then if-n*G>-1 and-n*G<1 then Direction=-n*G elseif-n*G>0 then Direction=1 elseif-n*G<0 then Direction=-1 end if-T>-1 and-T<1 then Steer=-T elseif-T>0 then Steer=1 elseif-T<0 then Steer=-1 end end end)end UserInputService.InputBegan:connect(function(s,e)if WeldObject.Value~=nil then if s.KeyCode==Enum.KeyCode.Space or s.KeyCode==Enum.KeyCode.Backspace or s.KeyCode==Enum.KeyCode.ButtonA then Hopoff()end if s.KeyCode==Enum.KeyCode.W or s.KeyCode==Enum.KeyCode.Up or s.KeyCode==Enum.KeyCode.ButtonR2 then if Direction~=1 then Direction=1 end end if s.KeyCode==Enum.KeyCode.S or s.KeyCode==Enum.KeyCode.Down or s.KeyCode==Enum.KeyCode.ButtonL2 then if Direction~=-1 then Direction=-1 end end if s.KeyCode==Enum.KeyCode.D or s.KeyCode==Enum.KeyCode.Right then if Steer~=1 then Steer=1 end end if s.KeyCode==Enum.KeyCode.A or s.KeyCode==Enum.KeyCode.Left then if Steer~=-1 then Steer=-1 end end end end)
-- If using VR
if UserInputService.VREnabled and VRUseHeadsetControls.Value == true then
	VRService.UserCFrameChanged:connect(function(CFrametype, VRSpot)
		local x, y = VRSpot:toEulerAnglesXYZ()
		local Sensitivity = 1.2

		if CFrametype == Enum.UserCFrame.Head then
			-- Direction
			if -x * Sensitivity > -1 and -x * Sensitivity < 1 then -- Makes sure the headset isn't tilted too much
				Direction = -x * Sensitivity
			elseif -x * Sensitivity > 0 then -- Otherwise we'll go to the max speed
				Direction = 1
			elseif -x * Sensitivity < 0 then -- Otherwise we'll go to the max speed
				Direction = -1
			end

			-- Steering
			if -y > -1 and -y < 1 then -- Makes sure the headset isn't tilted too much
				Steer = -y
			elseif -y > 0 then -- Otherwise we'll go to the max speed
				Steer = 1
			elseif -y < 0 then -- Otherwise we'll go to the max speed
				Steer = -1
			end
		end
	end)
end

UserInputService.InputBegan:connect(function(Key, ProcessedEvent)
	if WeldObject.Value ~= nil then
		-- Hop off segway if press Spacebar, Backspace or controller A button
		if
			Key.KeyCode == Enum.KeyCode.Space
			or Key.KeyCode == Enum.KeyCode.Backspace
			or Key.KeyCode == Enum.KeyCode.ButtonA
		then
			Hopoff()
		end

		--Forward
		if Key.KeyCode == Enum.KeyCode.W or Key.KeyCode == Enum.KeyCode.Up or Key.KeyCode == Enum.KeyCode.ButtonR2 then
			if Direction ~= 1 then
				Direction = 1
			end
		end

		--Backward
		if
			Key.KeyCode == Enum.KeyCode.S
			or Key.KeyCode == Enum.KeyCode.Down
			or Key.KeyCode == Enum.KeyCode.ButtonL2
		then
			if Direction ~= -1 then
				Direction = -1
			end
		end

		--Left
		if Key.KeyCode == Enum.KeyCode.D or Key.KeyCode == Enum.KeyCode.Right then
			if Steer ~= 1 then
				Steer = 1
			end
		end

		--Right
		if Key.KeyCode == Enum.KeyCode.A or Key.KeyCode == Enum.KeyCode.Left then
			if Steer ~= -1 then
				Steer = -1
			end
		end
	end
end)
